Class: HasManyWithSet::MigrationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/has_many_with_set/migration_generator.rb

Constant Summary collapse

ORM_IDENTIFIER_SIZE_LIMIT =
63

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childObject

Returns the value of attribute child.



18
19
20
# File 'lib/generators/has_many_with_set/migration_generator.rb', line 18

def child
  @child
end

#parentObject

Returns the value of attribute parent.



18
19
20
# File 'lib/generators/has_many_with_set/migration_generator.rb', line 18

def parent
  @parent
end

Class Method Details

.next_migration_number(path) ⇒ Object



9
10
11
# File 'lib/generators/has_many_with_set/migration_generator.rb', line 9

def self.next_migration_number(path)
  Time.now.utc.strftime("%Y%m%d%H%M%S")
end

Instance Method Details

#create_migration_fileObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/has_many_with_set/migration_generator.rb', line 21

def create_migration_file
  @parent_table = parent.tableize
  @child_table = child.tableize
  @set_table = "#{ @parent_table }_#{ @child_table }_sets"
  @set_items_table = "#{ @set_table }_#{ @child_table }"
  @migration_class_name = "create_#{ @set_table }".classify
  @items_table_set_table_index = "ix_items_#{ @set_items_table }"[0,  ORM_IDENTIFIER_SIZE_LIMIT]
  @items_table_child_table_index = "ix_#{ @child_table }_#{ @set_items_table }"[0,  ORM_IDENTIFIER_SIZE_LIMIT]

  migration_template "sets.rb.erb", "db/migrate/#{ @migration_class_name.tableize.singularize }.rb"
end