Class: MigrationDefs::Column

Inherits:
AbstractMigrationClass show all
Defined in:
lib/migration_defs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name = '', *p_option) ⇒ Column

Returns a new instance of Column.



189
190
191
192
193
194
195
# File 'lib/migration_defs.rb', line 189

def initialize(type, name = '', *p_option)
  return nil if !ColumnType.has_key?(type)

  @type = type
  @name = name
  @option = ColumnOption.new
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



187
188
189
# File 'lib/migration_defs.rb', line 187

def name
  @name
end

#optionObject

Returns the value of attribute option.



187
188
189
# File 'lib/migration_defs.rb', line 187

def option
  @option
end

#typeObject

Returns the value of attribute type.



187
188
189
# File 'lib/migration_defs.rb', line 187

def type
  @type
end

Instance Method Details

#get_str(prefix = 't.') ⇒ Object



212
213
214
215
216
# File 'lib/migration_defs.rb', line 212

def get_str(prefix = 't.')
  result = prefix + @type
  result += " :#{@name}" if (@type != 'timestamps') && (@type != 'attachment')
  result += @option.get_str
end

#set_option(key, val) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/migration_defs.rb', line 197

def set_option(key, val)
  case key
  when 'limit'
    @option.limit = val.to_i
  when 'default'
    @option.default = val
  when 'null'
    @option.null = (val == 'true')
  when 'precision'
    @option.precision = val.to_i
  when 'scale'
    @option.scale = val.to_i
  end
end