Module: ActiveGraph::Generators::MigrationHelper
- Extended by:
- ActiveSupport::Concern
- Included in:
- MigrationGenerator, ModelGenerator, UpgradeV8Generator
- Defined in:
- lib/rails/generators/migration_helper.rb
Instance Method Summary collapse
- #base_migration_file_name(file_name, prefix = '') ⇒ Object
- #existing_migration(dirname, file_name) ⇒ Object
- #migration_file_name(file_name, prefix = '') ⇒ Object
- #migration_lookup_at(dirname) ⇒ Object
-
#migration_template(template_name, prefix = '') ⇒ Object
:revoke happens when task is invoked with ‘rails destroy model ModelName`.
Instance Method Details
#base_migration_file_name(file_name, prefix = '') ⇒ Object
9 10 11 |
# File 'lib/rails/generators/migration_helper.rb', line 9 def base_migration_file_name(file_name, prefix = '') "#{prefix}#{file_name.parameterize}" end |
#existing_migration(dirname, file_name) ⇒ Object
22 23 24 |
# File 'lib/rails/generators/migration_helper.rb', line 22 def existing_migration(dirname, file_name) migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first end |
#migration_file_name(file_name, prefix = '') ⇒ Object
13 14 15 |
# File 'lib/rails/generators/migration_helper.rb', line 13 def migration_file_name(file_name, prefix = '') "#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{base_migration_file_name(file_name, prefix)}.rb" end |
#migration_lookup_at(dirname) ⇒ Object
17 18 19 |
# File 'lib/rails/generators/migration_helper.rb', line 17 def migration_lookup_at(dirname) Dir.glob("#{dirname}/[0-9]*_*.rb") end |
#migration_template(template_name, prefix = '') ⇒ Object
:revoke happens when task is invoked with ‘rails destroy model ModelName`
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rails/generators/migration_helper.rb', line 27 def migration_template(template_name, prefix = '') real_file_name = case @behavior when :revoke existing_migration( 'db/neo4j/migrate', base_migration_file_name(file_name, prefix) ) else migration_file_name(file_name, prefix) end # If running with :revoke and migration doesn't exist, real_file_name = nil return if !real_file_name @migration_class_name = file_name.camelize # template() method is still run on revoke but it doesn't generate anything # other than a consol message indicating the filepath. # (this appears to be behavior provided by rails) template template_name, File.join('db/neo4j/migrate', real_file_name) # On revoke, we need to manually remove the file FileUtils.rm(real_file_name) if @behavior == :revoke end |