Module: Intermodal::Models::Accountability::Get

Included in:
HasParentResource::ClassMethods
Defined in:
lib/intermodal/concerns/models/accountability.rb

Instance Method Summary collapse

Instance Method Details

#build_get_query(_query, opts) ⇒ Object

API: overrideable Use this to extend Get



26
27
28
29
30
# File 'lib/intermodal/concerns/models/accountability.rb', line 26

def build_get_query(_query, opts)
  _query = _query.(opts[:account]) if opts[:account]
  _query = _query.(opts[:account_id]) if opts[:account_id]
  return _query
end

#get(_id, opts = {}) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/intermodal/concerns/models/accountability.rb', line 32

def get(_id, opts = {})
  # Rails 4 no longer has .scoped, and where(nil) is the actual replacement
  # always returning a relation
  # See: http://stackoverflow.com/a/18199294/313193
  _query = build_get_query(self.where(nil), opts)
  return _query if _id == :all

  # Force false on readonly
  _resource = _query.where(:id => _id).limit(1).readonly(false).first
  raise ActiveRecord::RecordNotFound, "Could not find resource" unless _resource
  return _resource
end