Class: SimpleRecord::Attributes::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_record/attributes.rb

Overview

Holds information about an attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options = nil) ⇒ Attribute

Returns a new instance of Attribute.



413
414
415
416
# File 'lib/simple_record/attributes.rb', line 413

def initialize(type, options=nil)
  @type = type
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



411
412
413
# File 'lib/simple_record/attributes.rb', line 411

def options
  @options
end

#typeObject

Returns the value of attribute type.



411
412
413
# File 'lib/simple_record/attributes.rb', line 411

def type
  @type
end

Instance Method Details

#init_value(value) ⇒ Object



418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/simple_record/attributes.rb', line 418

def init_value(value)
  return value if value.nil?
  ret = value
  case self.type
    when :int
      if value.is_a? Array
        ret = value.collect { |x| x.to_i }
      else
        ret = value.to_i
      end
  end
  ret
end