Module: Neo4j::Generators::MigrationHelper
- Extended by:
- ActiveSupport::Concern
- Included in:
- MigrationGenerator, ModelGenerator, UpgradeV8Generator
- Defined in:
- lib/rails/generators/neo4j_generator.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
12 13 14 |
# File 'lib/rails/generators/neo4j_generator.rb', line 12 def base_migration_file_name(file_name, prefix = '') "#{prefix}#{file_name.parameterize}" end |
#existing_migration(dirname, file_name) ⇒ Object
25 26 27 |
# File 'lib/rails/generators/neo4j_generator.rb', line 25 def existing_migration(dirname, file_name) migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first end |
#migration_file_name(file_name, prefix = '') ⇒ Object
16 17 18 |
# File 'lib/rails/generators/neo4j_generator.rb', line 16 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
20 21 22 |
# File 'lib/rails/generators/neo4j_generator.rb', line 20 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`
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rails/generators/neo4j_generator.rb', line 30 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 |