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.
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?
38
39
40
41
42
43
|
# File 'lib/cistern/model.rb', line 38
def ==(comparison_object)
super ||
(comparison_object.is_a?(self.class) &&
comparison_object.identity == self.identity &&
!comparison_object.new_record?)
end
|
#hash ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/cistern/model.rb', line 47
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
28
29
30
31
32
33
34
35
36
|
# File 'lib/cistern/model.rb', line 28
def reload
requires :identity
if data = collection.get(identity)
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
end
|
#save ⇒ Object
24
25
26
|
# File 'lib/cistern/model.rb', line 24
def save
raise NotImplementedError
end
|
#service ⇒ Object
55
56
57
|
# File 'lib/cistern/model.rb', line 55
def service
self.connection ? self.connection.class : Cistern
end
|
#update(attributes) ⇒ Object
19
20
21
22
|
# File 'lib/cistern/model.rb', line 19
def update(attributes)
merge_attributes(attributes)
save
end
|
#wait_for(timeout = self.service.timeout, interval = self.service.poll_interval, &block) ⇒ Object
59
60
61
|
# File 'lib/cistern/model.rb', line 59
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
63
64
65
|
# File 'lib/cistern/model.rb', line 63
def wait_for!(timeout = self.service.timeout, interval = self.service.poll_interval, &block)
service.wait_for!(timeout, interval) { reload && block.call(self) }
end
|