Class: ContextualConfig::Generators::ConfigurableTableGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/contextual_config/configurable_table/configurable_table_generator.rb

Overview

Generates a migration to create a table suitable for models that will include ContextualConfig's concerns.

To run this generator:

rails generate contextual_config:configurable_table YourModelName
rails generate contextual_config:configurable_table Namespace::YourModelName
rails generate contextual_config:configurable_table UserPreference --table-name user_prefs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Required by ActiveRecord::Generators::Migration to create timestamped migration filenames.



37
38
39
# File 'lib/generators/contextual_config/configurable_table/configurable_table_generator.rb', line 37

def self.next_migration_number(dirname)
  ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Instance Method Details

#create_migration_fileObject

The main method executed by the generator



25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/contextual_config/configurable_table/configurable_table_generator.rb', line 25

def create_migration_file
  # migration_template will copy the template file to the application's db/migrate directory.
  # It automatically handles the timestamp for the migration filename.
  # Instance variables set here (like @migration_table_name) are available in the template.
  @migration_table_name = determine_table_name_for_migration

  migration_template('migration.rb.tt', # Template file name
                     "db/migrate/create_#{@migration_table_name}.rb", # Destination path
                     migration_version: migration_version_string) # For Rails 5+ migration versions
end

#migration_class_nameObject



65
66
67
# File 'lib/generators/contextual_config/configurable_table/configurable_table_generator.rb', line 65

def migration_class_name
  "Create#{determine_table_name_for_migration.camelize}"
end