Class: Shaf::Generator::Migration::CreateTable
- Inherits:
-
Base
- Object
- Base
- Shaf::Generator::Migration::CreateTable
show all
- Defined in:
- lib/shaf/generator/migration/create_table.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
#compile_changes ⇒ Object
18
19
20
|
# File 'lib/shaf/generator/migration/create_table.rb', line 18
def compile_changes
add_change create_table_change
end
|
#compile_migration_name ⇒ Object
14
15
16
|
# File 'lib/shaf/generator/migration/create_table.rb', line 14
def compile_migration_name
"create_#{table_name}_table"
end
|
#create_table_change ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/shaf/generator/migration/create_table.rb', line 22
def create_table_change
cols = ["primary_key :id"]
cols += ["DateTime :created_at", "DateTime :updated_at"] if add_timestamp_columns?
cols += args[1..-1].map { |s| column_def(s) }
[
"create_table(:#{table_name}) do",
*cols.map { |col| col.prepend(" ") }, "end\n\n"
]
end
|
#validate_args ⇒ Object
9
10
11
12
|
# File 'lib/shaf/generator/migration/create_table.rb', line 9
def validate_args
return unless table_name.empty?
raise "Please provide a table name when generation a create table migration"
end
|