Class: MigrationDefs::AddColumnFunc
- Inherits:
- 
      AbstractMigrationClass
      
        - Object
- AbstractMigrationClass
- MigrationDefs::AddColumnFunc
 
- Defined in:
- lib/migration_defs.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- 
  
    
      #column  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute column. 
- 
  
    
      #name  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute name. 
Instance Method Summary collapse
- #add_column(type, name = '') ⇒ Object
- #get_str ⇒ Object
- 
  
    
      #initialize(name)  ⇒ AddColumnFunc 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of AddColumnFunc. 
- #parse_from_params(parse_params) ⇒ Object
Constructor Details
#initialize(name) ⇒ AddColumnFunc
Returns a new instance of AddColumnFunc.
| 352 353 354 | # File 'lib/migration_defs.rb', line 352 def initialize(name) @name = name end | 
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
| 350 351 352 | # File 'lib/migration_defs.rb', line 350 def column @column end | 
#name ⇒ Object
Returns the value of attribute name.
| 350 351 352 | # File 'lib/migration_defs.rb', line 350 def name @name end | 
Instance Method Details
#add_column(type, name = '') ⇒ Object
| 356 357 358 | # File 'lib/migration_defs.rb', line 356 def add_column(type, name = '') @column = Column.new(type, name) end | 
#get_str ⇒ Object
| 373 374 375 376 377 378 379 380 381 382 383 | # File 'lib/migration_defs.rb', line 373 def get_str if @column.nil? return "add_column :#{@name}\n" else if (@column.type != 'timestamps') && (@column.type != 'attachment') && (@column.type != 'belongs_to') return "add_column :#{@name}" + (@column.name.blank? ? "\n" : ", :#{@column.name}, :#{@column.type}#{@column.option.get_str}\n") else return "add_column :#{@name}, #{:@column.type}\n" end end end | 
#parse_from_params(parse_params) ⇒ Object
| 360 361 362 363 364 365 366 367 368 369 370 371 | # File 'lib/migration_defs.rb', line 360 def parse_from_params(parse_params) if (parse_params[:type] != 'timestamps') && (parse_params[:type] != 'attachment') && (parse_params[:type] != 'belongs_to') @column = add_column(parse_params[:type], parse_params[:column]) @column.set_option 'limit', parse_params[:limit] @column.set_option 'default', parse_params[:default] @column.set_option 'null', parse_params[:null] @column.set_option 'precision', parse_params[:precision] @column.set_option 'scale', parse_params[:scale] else add_column(parse_params[:type]) end end |