Module: IdentityMap
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/projectile/identity_map.rb', line 3 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#merge_with_json(json) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/projectile/identity_map.rb', line 65 def merge_with_json(json) self.class.get_relationships.each do |relationship| name = relationship[:name] default = relationship[:default] key_path = relationship[:key_path] json_value = json.valueForKeyPath(key_path) self.send("#{name}=", json_value) unless json_value.nil? end self.class.get_attributes.each do |attribute| name = attribute[:name] default = attribute[:default] key_path = attribute[:key_path] default = attribute[:default] json_value = json.valueForKeyPath(key_path) self.send("#{name}=", json_value) unless json_value.nil? || json_value == default end end |
#merge_with_model(model) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/projectile/identity_map.rb', line 48 def merge_with_model(model) return unless self.is_a?(model.class) self.class.get_relationships.each do |relationship| name = relationship[:name] model_value = model.send("#{name}") self.send("#{name}=", model_value) unless model_value.nil? end self.class.get_attributes.each do |attribute| name = attribute[:name] model_value = model.send("#{name}") default = attribute[:default] self.send("#{name}=", model_value) unless model_value.nil? || model_value == default end end |