Class: Shaf::Generator::Migration::DropColumn

Inherits:
Base
  • Object
show all
Defined in:
lib/shaf/generator/migration/drop_column.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#add_change, #call, #column_def, identified_by, identifier, inherited, #initialize, #table_name, #target, usage

Constructor Details

This class inherits a constructor from Shaf::Generator::Migration::Base

Instance Method Details

#columnObject



27
28
29
# File 'lib/shaf/generator/migration/drop_column.rb', line 27

def column
  args[1] || ""
end

#compile_changesObject



23
24
25
# File 'lib/shaf/generator/migration/drop_column.rb', line 23

def compile_changes
  add_change drop_column_change
end

#compile_migration_nameObject



19
20
21
# File 'lib/shaf/generator/migration/drop_column.rb', line 19

def compile_migration_name
  "drop_#{column}_from_#{table_name}"
end

#drop_column_changeObject



31
32
33
34
35
36
37
# File 'lib/shaf/generator/migration/drop_column.rb', line 31

def drop_column_change
  [
    "alter_table(:#{table_name}) do",
    "  drop_column :#{column}",
    "end\n"
  ]
end

#validate_argsObject



9
10
11
12
13
14
15
16
17
# File 'lib/shaf/generator/migration/drop_column.rb', line 9

def validate_args
  if table_name.empty?
    raise "Please provide a table and at least " \
      "one column when generation add column migration"
  elsif column.empty?
    raise "Please provide at least one column when " \
      "generation add column migration"
  end
end