module Attribrutal::Model

Public Class Methods

included(base) click to toggle source
# File lib/attribrutal/model.rb, line 5
def self.included(base)
  base.extend ClassMethods
end
new( attrs = {} ) click to toggle source
# 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

Public Instance Methods

attribute_keys() click to toggle source
# File lib/attribrutal/model.rb, line 27
def attribute_keys
  self.class.attribute_keys
end
attributes() click to toggle source
# 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
raw_attributes() click to toggle source
# File lib/attribrutal/model.rb, line 16
def raw_attributes
  @raw_attributes
end