lib/ridgepole/dsl_parser.rb in ridgepole-0.4.0 vs lib/ridgepole/dsl_parser.rb in ridgepole-0.4.1
- old
+ new
@@ -6,10 +6,12 @@
def initialize
@__definition = {}
end
def column(name, type, options = {})
+ name = name.to_s
+
@__definition[name] = {
:type => type,
:options => options,
}
end
@@ -55,11 +57,17 @@
ctx.__definition
end
def create_table(table_name, options = {})
+ table_name = table_name.to_s
table_definition = TableDefinition.new
+
+ [:primary_key].each do |key|
+ options[key] = options[key].to_s if options[key]
+ end
+
yield(table_definition)
@__definition[table_name] ||= {}
if @__definition[table_name][:definition]
raise "Table `#{table_name}` already defined"
@@ -69,9 +77,12 @@
options.delete(:force)
@__definition[table_name][:options] = options
end
def add_index(table_name, column_name, options = {})
+ table_name = table_name.to_s
+ column_name = [column_name].flatten.map {|i| i.to_s }
+ options[:name] = options[:name].to_s if options[:name]
@__definition[table_name] ||= {}
@__definition[table_name][:indices] ||= {}
idx = options[:name] || column_name
if @__definition[table_name][:indices][idx]