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
184 185 186 187 188 189 190 |
# File 'lib/cassandra_object/persistence.rb', line 184 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
158 159 160 161 162 163 164 165 166 |
# File 'lib/cassandra_object/persistence.rb', line 158 def destroy if self.class.schema_type == :standard self.class.delete_schema self else self.class.remove(id) end @destroyed = true end |
#destroyed? ⇒ Boolean
146 147 148 |
# File 'lib/cassandra_object/persistence.rb', line 146 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
142 143 144 |
# File 'lib/cassandra_object/persistence.rb', line 142 def new_record? @new_record end |
#persisted? ⇒ Boolean
150 151 152 |
# File 'lib/cassandra_object/persistence.rb', line 150 def persisted? !(new_record? || destroyed?) end |
#reload ⇒ Object
192 193 194 195 196 |
# File 'lib/cassandra_object/persistence.rb', line 192 def reload clear_belongs_to_cache @model_attributes = self.class.find(id).instance_variable_get('@model_attributes') self end |
#save ⇒ Object
154 155 156 |
# File 'lib/cassandra_object/persistence.rb', line 154 def save(*) new_record? ? create : update end |
#update_attribute(name, value) ⇒ Object
168 169 170 171 172 |
# File 'lib/cassandra_object/persistence.rb', line 168 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(validate: false) end |
#update_attributes(attributes) ⇒ Object
174 175 176 177 |
# File 'lib/cassandra_object/persistence.rb', line 174 def update_attributes(attributes) self.attributes = attributes save end |
#update_attributes!(attributes) ⇒ Object
179 180 181 182 |
# File 'lib/cassandra_object/persistence.rb', line 179 def update_attributes!(attributes) self.attributes = attributes save! end |