Class: MigrationDefs::CreateTableFunc
- Inherits:
-
AbstractMigrationClass
- Object
- AbstractMigrationClass
- MigrationDefs::CreateTableFunc
- Defined in:
- lib/migration_defs.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#name ⇒ Object
Returns the value of attribute name.
-
#option ⇒ Object
Returns the value of attribute option.
Instance Method Summary collapse
- #add_column(type, name = '') ⇒ Object
- #get_str ⇒ Object
-
#initialize(name) ⇒ CreateTableFunc
constructor
A new instance of CreateTableFunc.
- #parse_from_params(parse_params) ⇒ Object
Constructor Details
#initialize(name) ⇒ CreateTableFunc
Returns a new instance of CreateTableFunc.
268 269 270 271 272 |
# File 'lib/migration_defs.rb', line 268 def initialize(name) @name = name @option = CreateTableOption.new @columns = Array.new end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
266 267 268 |
# File 'lib/migration_defs.rb', line 266 def columns @columns end |
#name ⇒ Object
Returns the value of attribute name.
266 267 268 |
# File 'lib/migration_defs.rb', line 266 def name @name end |
#option ⇒ Object
Returns the value of attribute option.
266 267 268 |
# File 'lib/migration_defs.rb', line 266 def option @option end |
Instance Method Details
#add_column(type, name = '') ⇒ Object
274 275 276 277 |
# File 'lib/migration_defs.rb', line 274 def add_column(type, name = '') @columns << Column.new(type, name) @columns.last end |
#get_str ⇒ Object
302 303 304 305 306 307 308 309 310 |
# File 'lib/migration_defs.rb', line 302 def get_str result = "create_table :#{@name}" result += @option.get_str if !@option.nil? result += " do |t|\n" @columns.each do |col| result += col.get_str + "\n" if !col.nil? end result += "end\n" end |
#parse_from_params(parse_params) ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/migration_defs.rb', line 279 def parse_from_params(parse_params) return '' if parse_params.nil? || parse_params[:columns].nil? parse_params.each do |key, val| @option.set_option(key, val) end parse_params[:columns].each do |key, val| next if val.nil? if (val[:type] != 'timestamps') && (val[:type] != 'attachment') && (val[:type] != 'belongs_to') c = add_column(val[:type], val[:name]) c.set_option 'limit', val[:limit] c.set_option 'default', val[:default] c.set_option 'null', val[:null] c.set_option 'precision', val[:precision] c.set_option 'scale', val[:scale] else c = add_column(val[:type]) end end end |