lib/erd/migrator.rb in erd-0.2.0 vs lib/erd/migrator.rb in erd-0.3.0

- old
+ new

@@ -38,28 +38,40 @@ end end #TODO unload migraion classes end + # 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) - overwriting_argv([name, options]) do - Rails::Generators.configure! Rails.application.config.generators - result = Rails::Generators.invoke 'migration', [name, options], :behavior => :invoke, :destination_root => Rails.root - raise ::Erd::MigrationError, "#{name}#{"(#{options})" if options}" unless result - result.last.last - end + 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 Object.const_set :ARGV, value block.call ensure Object.const_set :ARGV, 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