Module: HOALife::Resources::Persistable

Extended by:
Concern
Includes:
Requestable
Included in:
Account, CCRArticle, CCRViolationType, Properties::SupplementalMailingAddress, Property, Violation
Defined in:
lib/hoalife/resources/persistable.rb

Overview

Persist an object

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concern

append_features, class_methods, extended, included

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



8
9
10
# File 'lib/hoalife/resources/persistable.rb', line 8

def errors
  @errors
end

Instance Method Details

#destroyObject



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

#idObject



16
17
18
# File 'lib/hoalife/resources/persistable.rb', line 16

def id
  attrs[:id]
end

#persisted?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/hoalife/resources/persistable.rb', line 32

def persisted?
  !id.nil?
end

#saveObject



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