Module: LogicalModel::Attributes::InstanceMethods

Defined in:
lib/logical_model/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logical_model/attributes.rb', line 15

def attributes
  attrs = self.class.attribute_keys.inject(ActiveSupport::HashWithIndifferentAccess.new) do |result,key|
    result[key] = read_attribute_for_validation(key)
    result
  end

  unless self.class.has_many_keys.blank?
    self.class.has_many_keys.inject(attrs) do |result,key|
      result["#{key}_attributes"] = send(key).map {|a| a.attributes}
      result
    end
  end
  attrs.reject {|key, value| key == "_id" && value.blank?}
end

#attributes=(attrs) ⇒ Object



11
12
13
# File 'lib/logical_model/attributes.rb', line 11

def attributes=(attrs)
  attrs.each{|k,v| send("#{k}=",v) if respond_to?("#{k}=")}
end