Class: Believer::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming, FinderMethods, Querying
Includes:
ActiveModel::Observing, Callbacks, Columns, Connection, Counting, DDL, Environment, ModelSchema, Persistence, Scoping
Defined in:
lib/believer/base.rb

Constant Summary

Constants included from Callbacks

Callbacks::CALLBACKS

Constants included from Environment

Environment::ENVIRONMENTS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FinderMethods

find

Methods included from Counting

#has_counter_diffs?, #is_counter_instance?

Methods included from Callbacks

#destroy, #save, #update

Methods included from Persistence

#destroy, #persisted!, #persisted?, #save

Methods included from Columns

#attribute_names, #attributes, #attributes=, #equal_key_values?, #has_attribute?, #key_values, #read_attribute, #write_attribute

Constructor Details

#initialize(attrs = {}) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



23
24
25
26
27
# File 'lib/believer/base.rb', line 23

def initialize(attrs = {})
  @attributes = {}
  set_attributes(attrs)
  yield self if block_given?
end

Instance Attribute Details

#idObject

The Cassandra row ID



21
22
23
# File 'lib/believer/base.rb', line 21

def id
  @id
end

Class Method Details

.instantiate_from_result_rows(row) ⇒ Object



29
30
31
# File 'lib/believer/base.rb', line 29

def self.instantiate_from_result_rows(row)
  new(row)
end

.loggerObject



57
58
59
# File 'lib/believer/base.rb', line 57

def self.logger
  environment.logger
end

Instance Method Details

#==(obj) ⇒ Object



47
48
49
# File 'lib/believer/base.rb', line 47

def ==(obj)
  eql?(obj)
end

#eql?(obj) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/believer/base.rb', line 51

def eql?(obj)
  return false if obj.nil?
  return false unless obj.is_a?(self.class)
  equal_key_values?(obj)
end

#reload!Object



33
34
35
36
37
38
39
# File 'lib/believer/base.rb', line 33

def reload!
  persisted_object = self.class.scoped.where(key_values).first
  unless persisted_object.nil?
    set_attributes(persisted_object.attributes)
  end
  self
end

#set_attributes(attrs) ⇒ Object



41
42
43
44
45
# File 'lib/believer/base.rb', line 41

def set_attributes(attrs)
  attrs.each do |name, val|
    send("#{name}=".to_sym, val)
  end if attrs.present?
end