Module: Superstore::Persistence
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
- #update(attributes) ⇒ Object (also: #update_attributes)
- #update!(attributes) ⇒ Object (also: #update_attributes!)
- #update_attribute(name, value) ⇒ Object
Instance Method Details
#destroy ⇒ Object
91 92 93 94 |
# File 'lib/superstore/persistence.rb', line 91 def destroy self.class.delete(id) @destroyed = true end |
#destroyed? ⇒ Boolean
79 80 81 |
# File 'lib/superstore/persistence.rb', line 79 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
75 76 77 |
# File 'lib/superstore/persistence.rb', line 75 def new_record? @new_record end |
#persisted? ⇒ Boolean
83 84 85 |
# File 'lib/superstore/persistence.rb', line 83 def persisted? !(new_record? || destroyed?) end |
#reload ⇒ Object
116 117 118 119 120 |
# File 'lib/superstore/persistence.rb', line 116 def reload clear_association_cache @attributes = self.class.find(id).instance_variable_get('@attributes') self end |
#save ⇒ Object
87 88 89 |
# File 'lib/superstore/persistence.rb', line 87 def save(*) create_or_update end |
#update(attributes) ⇒ Object Also known as: update_attributes
102 103 104 105 |
# File 'lib/superstore/persistence.rb', line 102 def update(attributes) self.attributes = attributes save end |
#update!(attributes) ⇒ Object Also known as: update_attributes!
109 110 111 112 |
# File 'lib/superstore/persistence.rb', line 109 def update!(attributes) self.attributes = attributes save! end |
#update_attribute(name, value) ⇒ Object
96 97 98 99 100 |
# File 'lib/superstore/persistence.rb', line 96 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(validate: false) end |