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

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

#destroyObject



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

#reloadObject



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

#saveObject



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