Class: Cistern::Model
Instance Attribute Summary collapse
Instance Method Summary
collapse
_load, aliases, attribute, attributes, identity, ignore_attributes, ignored_attributes
#_dump, #attributes, #attributes=, #changed, #dirty?, #dirty_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.
13
14
15
|
# File 'lib/cistern/model.rb', line 13
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
Also known as:
service
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?
36
37
38
39
40
41
|
# File 'lib/cistern/model.rb', line 36
def ==(comparison_object)
super ||
(comparison_object.is_a?(self.class) &&
comparison_object.identity == self.identity &&
!comparison_object.new_record?)
end
|
#hash ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/cistern/model.rb', line 45
def hash
if self.identity
[self.class, self.identity].join(":").hash
else
super
end
end
|
#inspect ⇒ Object
9
10
11
|
# File 'lib/cistern/model.rb', line 9
def inspect
Cistern.formatter.call(self)
end
|
#reload ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/cistern/model.rb', line 26
def reload
requires :identity
if data = collection.get(identity)
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
end
|
#save ⇒ Object
22
23
24
|
# File 'lib/cistern/model.rb', line 22
def save
raise NotImplementedError
end
|
#update(attributes) ⇒ Object
17
18
19
20
|
# File 'lib/cistern/model.rb', line 17
def update(attributes)
merge_attributes(attributes)
save
end
|
#wait_for(timeout = self.service.timeout, interval = self.service.poll_interval, &block) ⇒ Object
57
58
59
|
# File 'lib/cistern/model.rb', line 57
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
61
62
63
|
# File 'lib/cistern/model.rb', line 61
def wait_for!(timeout = self.service.timeout, interval = self.service.poll_interval, &block)
service.wait_for!(timeout, interval) { reload && block.call(self) }
end
|