Module: ActiveRepository::Writers::InstanceMethods
- Included in:
- Base
- Defined in:
- lib/active_repository/writers.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#attributes=(new_attributes) ⇒ Object
Assigns new_attributes parameter to the attributes in self.
-
#delete ⇒ Object
Deletes self from the repository.
-
#update_attribute(key, value) ⇒ Object
Updates #key attribute with #value value.
-
#update_attributes(attributes) ⇒ Object
Updates attributes in self with the attributes in the parameter.
Instance Method Details
#attributes=(new_attributes) ⇒ Object
Assigns new_attributes parameter to the attributes in self.
48 49 50 51 52 |
# File 'lib/active_repository/writers.rb', line 48 def attributes=(new_attributes) new_attributes.each do |k,v| self.send("#{k.to_s == '_id' ? 'id' : k.to_s}=", v) end end |
#delete ⇒ Object
Deletes self from the repository.
55 56 57 58 59 60 61 62 |
# File 'lib/active_repository/writers.rb', line 55 def delete klass = self.class if klass.get_model_class == klass super else PersistenceAdapter.delete(klass, self.id) end end |
#update_attribute(key, value) ⇒ Object
Updates #key attribute with #value value.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/active_repository/writers.rb', line 65 def update_attribute(key, value) ret = self.valid? if ret if self.class == self.class.get_model_class object = self.class.find_or_initialize(:id => self.id) self.send("#{key}=", value) ret = save else # key = (key.to_s == 'id' ? '_id' : key.to_s) if mongoid? ret, object = PersistenceAdapter.update_attribute(self.class, self.id, key, value) self.attributes = object.attributes # object.update_attribute(key,value) end reload end ret end |
#update_attributes(attributes) ⇒ Object
Updates attributes in self with the attributes in the parameter
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/active_repository/writers.rb', line 91 def update_attributes(attributes) ret = true klass = self.class model_class = self.class.get_model_class if klass == model_class attributes.each do |key, value| self.send("#{key}=", value) unless key == :id end save else attributes = self.attributes.merge(attributes) ret, object = PersistenceAdapter.update_attributes(self.class, self.id, attributes) self.attributes = object.attributes # object = self.id.nil? ? model_class.new : model_class.find(self.id) # ret = object.update_attributes(attributes) end reload ret end |