Module: ActiveRecord::Migration::Ext::ChangeTableMoveToEnd::CommandRecorder::Ext

Defined in:
lib/active_record/migration/ext/change_table_move_to_end.rb

Instance Method Summary collapse

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_renameObject

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_namesObject



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_commandsObject



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_commandsObject



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