Class: SchemaRD::MigrationContext::Loader::TableDefinition
- Inherits:
-
Object
- Object
- SchemaRD::MigrationContext::Loader::TableDefinition
show all
- Defined in:
- lib/schemard/schema_parser.rb
Instance Method Summary
collapse
Constructor Details
#initialize(table, with_comment: false) ⇒ TableDefinition
“with_comment” must be assigned, but ruby2.0 needs default value.
30
31
32
33
|
# File 'lib/schemard/schema_parser.rb', line 30
def initialize(table, with_comment: false)
@table = table
@parse_db_comment =
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
34
35
36
|
# File 'lib/schemard/schema_parser.rb', line 34
def method_missing(name, *args)
self.column(args[0], "unknown", args[1])
end
|
Instance Method Details
#column(name, type, options = {}) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/schemard/schema_parser.rb', line 37
def column(name, type, options = {})
if options[:comment] && @parse_db_comment
options[:parsed_db_comment] = options.delete(:comment)
end
@table.columns << SchemaRD::TableColumn.new(options.merge({ name: name, type: type }))
end
|
#index(column_name, options = {}) ⇒ Object
47
48
49
50
|
# File 'lib/schemard/schema_parser.rb', line 47
def index(column_name, options = {})
column_name = [ column_name ] unless column_name.is_a?(Array)
@table.indexes << SchemaRD::TableIndex.new(options.merge({ columns: column_name }))
end
|
#timestamps ⇒ Object
43
44
45
46
|
# File 'lib/schemard/schema_parser.rb', line 43
def timestamps
column("created_at", :timestamp, null: false)
column("updated_at", :timestamp, null: false)
end
|