Module: Typecaster

Extended by:
ActiveSupport::Concern
Defined in:
lib/typecaster.rb,
lib/typecaster/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#attributesObject



50
51
52
# File 'lib/typecaster.rb', line 50

def attributes
  @attributes ||= self.class.attributes
end

#initialize(attributes = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/typecaster.rb', line 38

def initialize(attributes={})
  raw_attributes.each do |name, attributes|
    if attributes.has_key?(:default)
      define_instance_variable(name, attributes[:default])
    end
  end

  attributes.each do |key, value|
    send "#{key}=", value
  end
end

#raw_attributesObject



54
55
56
# File 'lib/typecaster.rb', line 54

def raw_attributes
  @raw_attributes ||= self.class.raw_attributes
end

#to_rowObject



58
59
60
# File 'lib/typecaster.rb', line 58

def to_row
  attributes.values.join("")
end