Module: ActiveRecord::Migration::Ext::ChangeTableMoveToEnd::CommandRecorder::Ext
- Defined in:
- lib/active_record/migration/ext/change_table_move_to_end.rb
Instance Method Summary collapse
- #add_suffix(suffix) ⇒ Object
-
#change_add_column_to_rename ⇒ Object
changes add_column to rename_column, asking the provided block to transform the name.
- #column_names ⇒ Object
- #filter_add_column_commands ⇒ Object
- #only_add_column_commands ⇒ Object
Instance Method Details
#add_suffix(suffix) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/active_record/migration/ext/change_table_move_to_end.rb', line 40 def add_suffix(suffix) only_add_column_commands.tap do |recorder| recorder.commands = commands.map do |(command, args, _block)| table_name, name, type = args name = "#{name}#{suffix}" [command, [table_name, name, type]] end end end |
#change_add_column_to_rename ⇒ Object
changes add_column to rename_column, asking the provided block to transform the name
51 52 53 54 55 56 57 58 |
# File 'lib/active_record/migration/ext/change_table_move_to_end.rb', line 51 def change_add_column_to_rename only_add_column_commands.tap do |recorder| recorder.commands = commands.map do |(_command, args, _block)| table_name, name, _type = args [:rename_column, [table_name, name, yield(name)]] end end end |
#column_names ⇒ Object
33 34 35 36 37 38 |
# File 'lib/active_record/migration/ext/change_table_move_to_end.rb', line 33 def column_names only_add_column_commands.commands.map do |(_command, args, _block)| _table_name, name, _type = args name end end |
#filter_add_column_commands ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record/migration/ext/change_table_move_to_end.rb', line 21 def filter_add_column_commands dup.tap do |recorder| recorder.commands = commands.map do |(command, args, block)| if command == :add_column yield [command, args, block] else [command, args, block] end end end end |
#only_add_column_commands ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/active_record/migration/ext/change_table_move_to_end.rb', line 13 def only_add_column_commands dup.tap do |recorder| recorder.commands = commands.select do |(command, _args, _block)| command == :add_column end end end |