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
119 120 121 122 123 124 125 |
# File 'lib/cassandra_object/persistence.rb', line 119 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
98 99 100 101 |
# File 'lib/cassandra_object/persistence.rb', line 98 def destroy self.class.remove(id) @destroyed = true end |
#destroyed? ⇒ Boolean
86 87 88 |
# File 'lib/cassandra_object/persistence.rb', line 86 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
82 83 84 |
# File 'lib/cassandra_object/persistence.rb', line 82 def new_record? @new_record end |
#persisted? ⇒ Boolean
90 91 92 |
# File 'lib/cassandra_object/persistence.rb', line 90 def persisted? !(new_record? || destroyed?) end |
#reload ⇒ Object
127 128 129 130 131 |
# File 'lib/cassandra_object/persistence.rb', line 127 def reload clear_belongs_to_cache @attributes = self.class.find(id).instance_variable_get('@attributes') self end |
#save ⇒ Object
94 95 96 |
# File 'lib/cassandra_object/persistence.rb', line 94 def save(*) new_record? ? create : update end |
#update_attribute(name, value) ⇒ Object
103 104 105 106 107 |
# File 'lib/cassandra_object/persistence.rb', line 103 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(validate: false) end |
#update_attributes(attributes) ⇒ Object
109 110 111 112 |
# File 'lib/cassandra_object/persistence.rb', line 109 def update_attributes(attributes) self.attributes = attributes save end |
#update_attributes!(attributes) ⇒ Object
114 115 116 117 |
# File 'lib/cassandra_object/persistence.rb', line 114 def update_attributes!(attributes) self.attributes = attributes save! end |