Class: Migsupo::Generator::MigrationBuilder
- Inherits:
-
Object
- Object
- Migsupo::Generator::MigrationBuilder
- Defined in:
- lib/migsupo/generator/migration_builder.rb
Instance Method Summary collapse
- #build(operations, class_name:) ⇒ Object
-
#build_table(table) ⇒ Object
Renders one create_table block (plus its add_index lines) - the same shape a Schemafile uses.
-
#initialize(rails_version: nil) ⇒ MigrationBuilder
constructor
A new instance of MigrationBuilder.
Constructor Details
#initialize(rails_version: nil) ⇒ MigrationBuilder
Returns a new instance of MigrationBuilder.
13 14 15 |
# File 'lib/migsupo/generator/migration_builder.rb', line 13 def initialize(rails_version: nil) @rails_version = rails_version end |
Instance Method Details
#build(operations, class_name:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/migsupo/generator/migration_builder.rb', line 17 def build(operations, class_name:) all_reversible = operations.all?(&:reversible?) body = if all_reversible indent("def change\n#{indent(render_operations(operations))}\nend", 2) else up = indent("def up\n#{indent(render_operations(operations, direction: :up))}\nend", 2) down = indent("def down\n#{indent(render_operations(operations, direction: :down))}\nend", 2) "#{up}\n\n#{down}" end <<~RUBY class #{class_name} < ActiveRecord::Migration#{version_suffix} #{body} end RUBY end |
#build_table(table) ⇒ Object
Renders one create_table block (plus its add_index lines) - the same shape a Schemafile uses.
37 38 39 |
# File 'lib/migsupo/generator/migration_builder.rb', line 37 def build_table(table) render_create_table(Differ::Operations::CreateTable.new(table)) end |