Class: Believer::Base
- Inherits:
-
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
find
Methods included from Counting
#decr_counter!, #has_counter_diffs?, #incr_counter!, #is_counter_instance?, #reset_counters!
Methods included from Callbacks
#destroy, #save, #update
#delete, #destroy, #persisted!, #persisted?, #save
Methods included from Columns
#attribute_names, #attributes, #attributes=, #attributes_dup, #equal_key_values?, #has_attribute?, #key_values, #merge_attributes, #read_attribute, #write_attribute
Constructor Details
#initialize(attrs = {}) {|_self| ... } ⇒ Base
Returns a new instance of Base.
25
26
27
28
|
# File 'lib/believer/base.rb', line 25
def initialize(attrs = {})
set_attributes(attrs)
yield self if block_given?
end
|
Instance Attribute Details
#id ⇒ Object
23
24
25
|
# File 'lib/believer/base.rb', line 23
def id
@id
end
|
Class Method Details
.instantiate_from_result_rows(row) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/believer/base.rb', line 30
def self.instantiate_from_result_rows(row)
unless apply_cql_result_row_conversion?
obj = new
obj.merge_attributes(row)
return obj
end
new(row)
end
|
.logger ⇒ Object
65
66
67
|
# File 'lib/believer/base.rb', line 65
def self.logger
environment.logger
end
|
Instance Method Details
#==(obj) ⇒ Object
55
56
57
|
# File 'lib/believer/base.rb', line 55
def ==(obj)
eql?(obj)
end
|
#eql?(obj) ⇒ Boolean
59
60
61
62
63
|
# File 'lib/believer/base.rb', line 59
def eql?(obj)
return false if obj.nil?
return false unless obj.is_a?(self.class)
equal_key_values?(obj)
end
|
#reload! ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/believer/base.rb', line 40
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
48
49
50
51
52
53
|
# File 'lib/believer/base.rb', line 48
def set_attributes(attrs)
@attributes = {}
attrs.each do |name, val|
send("#{name}=".to_sym, val)
end if attrs.present?
end
|