Sha256: 35a41952c361dc377661a1142dc094e7f84d70112094c77d360e352fcc6ac0e2
Contents?: true
Size: 1.3 KB
Versions: 10
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true require 'rails/generators' module Erd class GenaratorRunner class << self # runs `rails g model [name]` # @return generated migration filename def execute_generate_model(name, options = nil) result = execute_generator 'model', name, options result.flatten.grep(%r(/db/migrate/.*\.rb)) end # runs `rails g migration [name]` # @return generated migration filename def execute_generate_migration(name, options = nil) result = execute_generator 'migration', name, options result.last.last end private # a dirty workaround to make rspec-rails run def overwriting_argv(value, &block) original_argv = ARGV.dup ARGV.clear ARGV.concat value block.call ensure ARGV.clear ARGV.concat original_argv end def execute_generator(type, name, options = nil) overwriting_argv([name, options]) do Rails::Generators.configure! Rails.application.config.generators result = Rails::Generators.invoke type, [name, options], :behavior => :invoke, :destination_root => Rails.root raise ::Erd::MigrationError, "#{name}#{"(#{options})" if options}" unless result result end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems