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

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

Constant Summary

Constants inherited from Base

Base::DB_COL_TYPES

Instance Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods inherited from Base

#add_change, #call, #column_def, #db_type, identifier, inherited, #initialize, #target, usage

Constructor Details

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

Instance Method Details

#columnObject



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

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



35
36
37
38
39
40
41
# File 'lib/shaf/generator/migration/drop_column.rb', line 35

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

#table_nameObject



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

def table_name
  args.first || ""
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