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
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #reload(options = nil) ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
- #update_attribute(name, value) ⇒ Object
- #update_attributes(attributes) ⇒ Object
- #update_attributes!(attributes) ⇒ Object
Instance Method Details
#destroy ⇒ Object
155 156 157 158 159 |
# File 'lib/cassandra_object/persistence.rb', line 155 def destroy self.class.remove(key) @destroyed = true freeze end |
#destroyed? ⇒ Boolean
135 136 137 |
# File 'lib/cassandra_object/persistence.rb', line 135 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
131 132 133 |
# File 'lib/cassandra_object/persistence.rb', line 131 def new_record? @new_record end |
#persisted? ⇒ Boolean
139 140 141 |
# File 'lib/cassandra_object/persistence.rb', line 139 def persisted? !(new_record? || destroyed?) end |
#reload(options = nil) ⇒ Object
177 178 179 180 181 |
# File 'lib/cassandra_object/persistence.rb', line 177 def reload( = nil) clear_association_cache @attributes.update(self.class.find(self.id).instance_variable_get('@attributes')) self end |
#save ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/cassandra_object/persistence.rb', line 143 def save(*) begin create_or_update rescue CassandraObject::RecordInvalid false end end |
#save! ⇒ Object
151 152 153 |
# File 'lib/cassandra_object/persistence.rb', line 151 def save! create_or_update || raise(RecordNotSaved) end |
#update_attribute(name, value) ⇒ Object
161 162 163 164 165 |
# File 'lib/cassandra_object/persistence.rb', line 161 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(:validate => false) end |
#update_attributes(attributes) ⇒ Object
167 168 169 170 |
# File 'lib/cassandra_object/persistence.rb', line 167 def update_attributes(attributes) self.attributes = attributes save end |
#update_attributes!(attributes) ⇒ Object
172 173 174 175 |
# File 'lib/cassandra_object/persistence.rb', line 172 def update_attributes!(attributes) self.attributes = attributes save! end |