Module: CassandraObject::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/cassandra_object/persistence.rb
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_attribute(name, value) ⇒ Object
- #update_attributes(attributes) ⇒ Object
- #update_attributes!(attributes) ⇒ Object
Instance Method Details
#becomes(klass) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/cassandra_object/persistence.rb', line 175 def becomes(klass) became = klass.new became.instance_variable_set('@model_attributes', @model_attributes) became.instance_variable_set('@new_record', new_record?) became.instance_variable_set('@destroyed', destroyed?) became end |
#destroy ⇒ Object
154 155 156 157 |
# File 'lib/cassandra_object/persistence.rb', line 154 def destroy self.class.remove(id) @destroyed = true end |
#destroyed? ⇒ Boolean
142 143 144 |
# File 'lib/cassandra_object/persistence.rb', line 142 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
138 139 140 |
# File 'lib/cassandra_object/persistence.rb', line 138 def new_record? @new_record end |
#persisted? ⇒ Boolean
146 147 148 |
# File 'lib/cassandra_object/persistence.rb', line 146 def persisted? !(new_record? || destroyed?) end |
#reload ⇒ Object
183 184 185 186 187 |
# File 'lib/cassandra_object/persistence.rb', line 183 def reload clear_belongs_to_cache @model_attributes = self.class.find(id).instance_variable_get('@model_attributes') self end |
#save ⇒ Object
150 151 152 |
# File 'lib/cassandra_object/persistence.rb', line 150 def save(*) new_record? ? create : update end |
#update_attribute(name, value) ⇒ Object
159 160 161 162 163 |
# File 'lib/cassandra_object/persistence.rb', line 159 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(validate: false) end |
#update_attributes(attributes) ⇒ Object
165 166 167 168 |
# File 'lib/cassandra_object/persistence.rb', line 165 def update_attributes(attributes) self.attributes = attributes save end |
#update_attributes!(attributes) ⇒ Object
170 171 172 173 |
# File 'lib/cassandra_object/persistence.rb', line 170 def update_attributes!(attributes) self.attributes = attributes save! end |