Module: Superstore::Persistence
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #becomes(klass) ⇒ Object
- #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
#becomes(klass) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/superstore/persistence.rb', line 127 def becomes(klass) became = klass.new became.instance_variable_set("@attributes", @attributes) became.instance_variable_set("@new_record", new_record?) became.instance_variable_set("@destroyed", destroyed?) became end |
#destroy ⇒ Object
102 103 104 105 |
# File 'lib/superstore/persistence.rb', line 102 def destroy self.class.remove(id) @destroyed = true end |
#destroyed? ⇒ Boolean
90 91 92 |
# File 'lib/superstore/persistence.rb', line 90 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
86 87 88 |
# File 'lib/superstore/persistence.rb', line 86 def new_record? @new_record end |
#persisted? ⇒ Boolean
94 95 96 |
# File 'lib/superstore/persistence.rb', line 94 def persisted? !(new_record? || destroyed?) end |
#reload ⇒ Object
135 136 137 138 139 |
# File 'lib/superstore/persistence.rb', line 135 def reload clear_belongs_to_cache @attributes = self.class.find(id).instance_variable_get('@attributes') self end |
#save ⇒ Object
98 99 100 |
# File 'lib/superstore/persistence.rb', line 98 def save(*) new_record? ? create_self : update_self end |
#update(attributes) ⇒ Object Also known as: update_attributes
113 114 115 116 |
# File 'lib/superstore/persistence.rb', line 113 def update(attributes) self.attributes = attributes save end |
#update!(attributes) ⇒ Object Also known as: update_attributes!
120 121 122 123 |
# File 'lib/superstore/persistence.rb', line 120 def update!(attributes) self.attributes = attributes save! end |
#update_attribute(name, value) ⇒ Object
107 108 109 110 111 |
# File 'lib/superstore/persistence.rb', line 107 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(validate: false) end |