Module: HOALife::Resources::Persistable
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Concern
append_features, class_methods, extended, included
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
8
9
10
|
# File 'lib/hoalife/resources/persistable.rb', line 8
def errors
@errors
end
|
Instance Method Details
#destroy ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/hoalife/resources/persistable.rb', line 46
def destroy
make_request! do
response = HOALife::Client::Delete.new(update_url)
response.status == 202
end
end
|
#id ⇒ Object
16
17
18
|
# File 'lib/hoalife/resources/persistable.rb', line 16
def id
attrs[:id]
end
|
#persisted? ⇒ Boolean
32
33
34
|
# File 'lib/hoalife/resources/persistable.rb', line 32
def persisted?
!id.nil?
end
|
#save ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/hoalife/resources/persistable.rb', line 20
def save
self.errors = nil
if !persisted?
create!
else
update!
end
errors.nil?
end
|
#update(attrs = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/hoalife/resources/persistable.rb', line 36
def update(attrs = {})
return false unless persisted?
attrs.each do |key, value|
send("#{key}=", value)
end
save
end
|