Class: Dao::Gateway::ActiveResource::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/dao/gateway/active_resource/base.rb

Instance Method Summary collapse

Instance Method Details

#chain(scope, method_name, args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dao/gateway/active_resource/base.rb', line 19

def chain(scope, method_name, args, &block)
  scope.public_send(method_name, *args, &block)
rescue ::ActiveResource::ResourceNotFound => e
  raise Dao::Gateway::RecordNotFound, e.message
rescue ::ActiveResource::ResourceInvalid => e
  errors = if e.response.is_a?(source)
    e.response.errors.to_hash
  elsif e.response.body.present?
    source.format.decode(e.response.body)
  else
    {}
  end
  raise Dao::Gateway::InvalidRecord.new(errors)
rescue ::ActiveResource::ForbiddenAccess => e
  raise Dao::Gateway::ForbiddenRecord, e.message
rescue ::ActiveResource::ConnectionError, Errno::ECONNREFUSED => e
  raise Dao::Gateway::BadConnection, e.to_s
end

#save!(domain, _) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dao/gateway/active_resource/base.rb', line 5

def save!(domain, _)
  record = export(domain, record(domain))
  record.save!

  domain.attributes = import(record, domain.initialized_with).attributes
  domain
rescue ::ActiveResource::ResourceInvalid
  raise Dao::Gateway::InvalidRecord.new(record.errors.to_hash)
rescue ::ActiveResource::ResourceNotFound => e
  raise Dao::Gateway::RecordNotFound, e.message
rescue ::ActiveResource::ConnectionError, Errno::ECONNREFUSED => e
  raise Dao::Gateway::BadConnection, e.to_s
end