Module: Believer::Persistence

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/believer/persistence.rb

Overview

Defines persistence functionality for a class

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#deleteObject

Deletes the Cassandra row.



44
45
46
# File 'lib/believer/persistence.rb', line 44

def delete
  Delete.new(:record_class => self.class).where(key_values).execute
end

#destroyObject

Destroys the model.



37
38
39
40
41
# File 'lib/believer/persistence.rb', line 37

def destroy
  res = self.delete
  @persisted = false
  res
end

#persisted!Object



48
49
50
# File 'lib/believer/persistence.rb', line 48

def persisted!
  @persisted = true
end

#persisted?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/believer/persistence.rb', line 52

def persisted?
  @persisted == true
end

#saveObject

Saves the model.



26
27
28
29
30
31
32
33
34
# File 'lib/believer/persistence.rb', line 26

def save
  if persisted? || is_counter_instance?
    Update.create(self).execute
  else
    Insert.new(:record_class => self.class, :values => self).execute
  end
  persisted!
  self
end