Class: Gris::Generators::MigrationGenerator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Gris::Generators::MigrationGenerator
- Includes:
- Thor::Actions
- Defined in:
- lib/gris/generators/migration_generator.rb
Instance Attribute Summary collapse
-
#join_tables ⇒ Object
readonly
Returns the value of attribute join_tables.
-
#migration_action ⇒ Object
readonly
Returns the value of attribute migration_action.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #migration ⇒ Object
- #migration_filename ⇒ Object
- #output_directory ⇒ Object
- #parse_attributes! ⇒ Object
- #set_local_assigns! ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#join_tables ⇒ Object (readonly)
Returns the value of attribute join_tables.
13 14 15 |
# File 'lib/gris/generators/migration_generator.rb', line 13 def join_tables @join_tables end |
#migration_action ⇒ Object (readonly)
Returns the value of attribute migration_action.
13 14 15 |
# File 'lib/gris/generators/migration_generator.rb', line 13 def migration_action @migration_action end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
13 14 15 |
# File 'lib/gris/generators/migration_generator.rb', line 13 def table_name @table_name end |
Instance Method Details
#migration ⇒ Object
53 54 55 56 57 58 |
# File 'lib/gris/generators/migration_generator.rb', line 53 def migration self.class.source_root "#{File.dirname(__FILE__)}/templates/#{@migration_template}" say 'Generating migration...' directory '.', output_directory say 'Done!', :green end |
#migration_filename ⇒ Object
19 20 21 |
# File 'lib/gris/generators/migration_generator.rb', line 19 def migration_filename "#{version}_#{migration_name.underscore}" end |
#output_directory ⇒ Object
23 24 25 |
# File 'lib/gris/generators/migration_generator.rb', line 23 def output_directory './db/migrate' end |
#parse_attributes! ⇒ Object
27 28 29 30 31 |
# File 'lib/gris/generators/migration_generator.rb', line 27 def parse_attributes! self.attributes = (attributes || []).map do |attr| GeneratedAttribute.parse(attr) end end |
#set_local_assigns! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gris/generators/migration_generator.rb', line 33 def set_local_assigns! @migration_template = 'migration' filename = migration_name.underscore case filename when /^(add|remove)_.*_(?:to|from)_(.*)/ @migration_action = Regexp.last_match[1] @table_name = Regexp.last_match[2].pluralize when /join_table/ if attributes.length == 2 @migration_action = 'join' @join_tables = attributes.map(&:plural_name) set_index_names end when /^create_(.+)/ @table_name = Regexp.last_match[1].pluralize @migration_template = 'create_table_migration' end end |
#version ⇒ Object
15 16 17 |
# File 'lib/gris/generators/migration_generator.rb', line 15 def version Time.now.utc.strftime('%Y%m%d%H%M%S') end |