Class: Shaf::Generator::Migration::AddIndex
- Inherits:
-
Base
- Object
- Base
- Shaf::Generator::Migration::AddIndex
show all
- Defined in:
- lib/shaf/generator/migration/add_index.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
Instance Method Details
#add_index_change ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/shaf/generator/migration/add_index.rb', line 27
def add_index_change
col_def = column_def("#{column}:index", create: false)
[
"alter_table(:#{table_name}) do",
col_def.prepend(" "), "end\n"
]
end
|
#column ⇒ Object
23
24
25
|
# File 'lib/shaf/generator/migration/add_index.rb', line 23
def column
args[1]
end
|
#compile_changes ⇒ Object
19
20
21
|
# File 'lib/shaf/generator/migration/add_index.rb', line 19
def compile_changes
add_change add_index_change
end
|
#compile_migration_name ⇒ Object
15
16
17
|
# File 'lib/shaf/generator/migration/add_index.rb', line 15
def compile_migration_name
"add_#{column}_index_to_#{table_name}"
end
|
#validate_args ⇒ Object
9
10
11
12
13
|
# File 'lib/shaf/generator/migration/add_index.rb', line 9
def validate_args
if (table_name || "").empty? || (column || "").empty?
raise "Please provide a table and the column to create index on"
end
end
|