Module: Attribrutal::Model

Defined in:
lib/attribrutal/model.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/attribrutal/model.rb', line 5

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#attribute_keysObject



27
28
29
# File 'lib/attribrutal/model.rb', line 27

def attribute_keys
  self.class.attribute_keys
end

#attributesObject



20
21
22
23
24
25
# File 'lib/attribrutal/model.rb', line 20

def attributes
  attribute_keys.inject(Hash.new) do |attributes, attribute|
    attributes[attribute] = self.send(attribute)
    attributes
  end
end

#initialize(attrs = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/attribrutal/model.rb', line 9

def initialize( attrs = {} )
  all_attributes         = attrs.symbolize_keys
  @raw_attributes        = all_attributes.select {|k,v| attribute_keys.include? k }
  other_attributes       = all_attributes.reject {|k,v| attribute_keys.include? k }
  other_attributes.map {|key, val| self.send("#{key}=", val) if respond_to?("#{key}=") }
end

#raw_attributesObject



16
17
18
# File 'lib/attribrutal/model.rb', line 16

def raw_attributes
  @raw_attributes
end