Module: CassandraModel::Persistence::InstanceMethods

Defined in:
lib/cassandra-model/persistence.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



25
26
27
28
29
30
# File 'lib/cassandra-model/persistence.rb', line 25

def destroy
  run_callbacks :before_destroy
  self.class.send(:remove, key)
  self.deleted!
  run_callbacks :after_destroy
end

#reloadObject



32
33
34
# File 'lib/cassandra-model/persistence.rb', line 32

def reload
  self.class.get(key)
end

#remove_attributes(attrs) ⇒ Object



41
42
43
# File 'lib/cassandra-model/persistence.rb', line 41

def remove_attributes(attrs)
  attrs.each {|attr| self.class.remove_column(key, attr) }
end

#saveObject

Raises:

  • (ActiveRecord::ReadOnlyRecord)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cassandra-model/persistence.rb', line 12

def save
  raise ActiveRecord::ReadOnlyRecord if readonly?
  return self unless valid?
  run_callbacks :before_save
  newrec = new_record?
  callback = newrec ? :before_create : :before_update
  run_callbacks callback
  write(attributes)
  callback = newrec ? :after_create : :after_update
  run_callbacks callback
  run_callbacks :after_save
end

#update_attributes(attrs) ⇒ Object



36
37
38
39
# File 'lib/cassandra-model/persistence.rb', line 36

def update_attributes(attrs)
  self.attributes = attrs
  save
end