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
173 174 175 176 177 178 179 |
# File 'lib/cassandra_object/persistence.rb', line 173 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
152 153 154 155 |
# File 'lib/cassandra_object/persistence.rb', line 152 def destroy self.class.remove(id) @destroyed = true end |
#destroyed? ⇒ Boolean
140 141 142 |
# File 'lib/cassandra_object/persistence.rb', line 140 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
136 137 138 |
# File 'lib/cassandra_object/persistence.rb', line 136 def new_record? @new_record end |
#persisted? ⇒ Boolean
144 145 146 |
# File 'lib/cassandra_object/persistence.rb', line 144 def persisted? !(new_record? || destroyed?) end |
#reload ⇒ Object
181 182 183 184 185 |
# File 'lib/cassandra_object/persistence.rb', line 181 def reload clear_belongs_to_cache @attributes = self.class.find(id).instance_variable_get('@attributes') self end |
#save ⇒ Object
148 149 150 |
# File 'lib/cassandra_object/persistence.rb', line 148 def save(*) new_record? ? create : update end |
#update_attribute(name, value) ⇒ Object
157 158 159 160 161 |
# File 'lib/cassandra_object/persistence.rb', line 157 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(validate: false) end |
#update_attributes(attributes) ⇒ Object
163 164 165 166 |
# File 'lib/cassandra_object/persistence.rb', line 163 def update_attributes(attributes) self.attributes = attributes save end |
#update_attributes!(attributes) ⇒ Object
168 169 170 171 |
# File 'lib/cassandra_object/persistence.rb', line 168 def update_attributes!(attributes) self.attributes = attributes save! end |