Class: Charming::Generators::MigrationGenerator
- Inherits:
-
AppFileGenerator
- Object
- Base
- AppFileGenerator
- Charming::Generators::MigrationGenerator
- Defined in:
- lib/charming/generators/migration_generator.rb
Overview
MigrationGenerator implements ‘charming generate migration NAME [field:type …]`. Follows Rails naming conventions:
-
‘create_<table>` generates a create_table migration (fields become columns)
-
‘add_<x>to<table>` generates add_column lines for the supplied fields
-
‘remove_<x>from<table>` generates remove_column lines
-
anything else generates an empty ‘change` method to fill in
Defined Under Namespace
Classes: Field
Constant Summary collapse
- VALID_TYPES =
The set of ActiveRecord column types accepted on the command line.
ModelGenerator::VALID_TYPES
Instance Method Summary collapse
-
#generate ⇒ Object
Validates database support, then writes the timestamped migration file.
-
#initialize(name, args, out:, destination:, force: false) ⇒ MigrationGenerator
constructor
A new instance of MigrationGenerator.
Constructor Details
#initialize(name, args, out:, destination:, force: false) ⇒ MigrationGenerator
Returns a new instance of MigrationGenerator.
18 19 20 21 |
# File 'lib/charming/generators/migration_generator.rb', line 18 def initialize(name, args, out:, destination:, force: false) super @fields = args.map { |arg| parse_field(arg) } end |
Instance Method Details
#generate ⇒ Object
Validates database support, then writes the timestamped migration file.
24 25 26 27 28 |
# File 'lib/charming/generators/migration_generator.rb', line 24 def generate raise Error, "Database support is not configured. Run `charming db:install sqlite3` first." unless database_configured? create_file(migration_path, migration) end |