Class: Cistern::Model
Instance Attribute Summary collapse
Instance Method Summary
collapse
_load, aliases, attribute, attributes, identity, ignore_attributes, ignored_attributes
#_dump, #attributes, #attributes=, #dup, #identity, #identity=, #merge_attributes, #new_record?, #read_attribute, #requires, #requires_one, #write_attribute
Constructor Details
#initialize(attributes = {}) ⇒ Model
Returns a new instance of Model.
15
16
17
|
# File 'lib/cistern/model.rb', line 15
def initialize(attributes={})
merge_attributes(attributes)
end
|
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
5
6
7
|
# File 'lib/cistern/model.rb', line 5
def collection
@collection
end
|
#connection ⇒ Object
Returns the value of attribute connection.
5
6
7
|
# File 'lib/cistern/model.rb', line 5
def connection
@connection
end
|
Instance Method Details
#==(comparison_object) ⇒ Object
Also known as:
eql?
33
34
35
36
37
38
|
# File 'lib/cistern/model.rb', line 33
def ==(comparison_object)
super ||
(comparison_object.is_a?(self.class) &&
comparison_object.identity == self.identity &&
!comparison_object.new_record?)
end
|
#hash ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/cistern/model.rb', line 42
def hash
if self.identity
[self.class, self.identity].join(":").hash
else
super
end
end
|
#inspect ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/cistern/model.rb', line 7
def inspect
if Cistern.formatter
Cistern.formatter.call(self)
else
"#<#{self.class} #{self.identity}"
end
end
|
#reload ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/cistern/model.rb', line 23
def reload
requires :identity
if data = collection.get(identity)
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
end
|
#save ⇒ Object
19
20
21
|
# File 'lib/cistern/model.rb', line 19
def save
raise NotImplementedError
end
|
#service ⇒ Object
50
51
52
|
# File 'lib/cistern/model.rb', line 50
def service
self.connection ? self.connection.class : Cistern
end
|
#wait_for(timeout = self.service.timeout, interval = self.service.poll_interval, &block) ⇒ Object
54
55
56
|
# File 'lib/cistern/model.rb', line 54
def wait_for(timeout = self.service.timeout, interval = self.service.poll_interval, &block)
service.wait_for(timeout, interval) { reload && block.call(self) }
end
|
#wait_for!(timeout = self.service.timeout, interval = self.service.poll_interval, &block) ⇒ Object
58
59
60
|
# File 'lib/cistern/model.rb', line 58
def wait_for!(timeout = self.service.timeout, interval = self.service.poll_interval, &block)
service.wait_for!(timeout, interval) { reload && block.call(self) }
end
|