The DSL where a line begins with a word, and then a list of parameters with a coma between them is actually a method call, so the original code is actually:
DB.create_table :items do
primary_key(:id)
String(:name)
Float(:price)
end
From the sequel documentation:
Most method calls inside the
create_table
block will create columns, sincemethod_missing
calls column. Columns are generally created by specifying the column type as the method name, followed by the column name symbol to use, and after that any options that should be used. If the method is a ruby class name that Sequel recognizes, Sequel will transform it into the appropriate type for the given database. So while you specifiedString
, Sequel will actually usevarchar
ortext
depending on the underlying database.
The create_table
block uses method_missing
to find out what you are trying to say. So what you could try to do is use send
instead:
my_db.create_table 'my_table' do
array_of_typed_columns.each do |tc|
column, type = tc.split(':')
send(type.capitalize, column.to_sym)
end
end