Class: ROM::SQL::Migration::Writer Private
- Inherits:
-
Object
- Object
- ROM::SQL::Migration::Writer
- Defined in:
- lib/rom/sql/migration/writer.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- MIGRATION_BEGIN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"ROM::SQL.migration do\n change do".freeze
- MIGRATION_END =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"\n end\nend\n".freeze
Instance Attribute Summary collapse
- #yield_migration ⇒ Object readonly private
Instance Method Summary collapse
- #create_migration(ops) ⇒ Object private
-
#initialize(&block) ⇒ Writer
constructor
private
A new instance of Writer.
- #migration {|recorder| ... } ⇒ Object private
- #migration_name(op) ⇒ Object private
- #write(operations, buffer, indent) ⇒ Object private
- #write_arguments(buffer, args) ⇒ Object private
Constructor Details
#initialize(&block) ⇒ Writer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Writer.
15 16 17 |
# File 'lib/rom/sql/migration/writer.rb', line 15 def initialize(&block) @yield_migration = block end |
Instance Attribute Details
#yield_migration ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/rom/sql/migration/writer.rb', line 13 def yield_migration @yield_migration end |
Instance Method Details
#create_migration(ops) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 |
# File 'lib/rom/sql/migration/writer.rb', line 25 def create_migration(ops) out = MIGRATION_BEGIN.dup write(ops, out, "\n ") out << MIGRATION_END [migration_name(ops[0]), out] end |
#migration {|recorder| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 23 |
# File 'lib/rom/sql/migration/writer.rb', line 19 def migration recorder = Recorder.new yield(recorder) yield_migration.(create_migration(recorder.operations)) end |
#migration_name(op) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 |
# File 'lib/rom/sql/migration/writer.rb', line 60 def migration_name(op) create_or_alter, args = op table_name = args[0] "#{create_or_alter.to_s.sub('_table', '')}_#{table_name}" end |
#write(operations, buffer, indent) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rom/sql/migration/writer.rb', line 33 def write(operations, buffer, indent) operations.each do |operation| op, args, nested = operation buffer << indent << op.to_s << ' ' write_arguments(buffer, args) if !nested.empty? buffer << ' do' write(nested, buffer, indent + ' ') buffer << indent << 'end' end end end |
#write_arguments(buffer, args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rom/sql/migration/writer.rb', line 47 def write_arguments(buffer, args) if args.last.is_a?(::Hash) args, = args[0...-1], args.last else = EMPTY_HASH end buffer << args.map(&:inspect).join(', ') .each do |key, value| buffer << ', ' << key.to_s << ': ' << value.inspect end end |