Class: Hexagonal::Responses::FindAllResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/hexagonal/responses/find_all_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, key, paginated: false, cache_method: nil) ⇒ FindAllResponse

Returns a new instance of FindAllResponse.



6
7
8
9
10
11
# File 'lib/hexagonal/responses/find_all_response.rb', line 6

def initialize(target, key, paginated: false, cache_method: nil)
  @target       = target
  @key          = key
  @paginated    = paginated
  @cache_method = cache_method
end

Instance Method Details

#found(objects) ⇒ Object



13
14
15
16
17
18
# File 'lib/hexagonal/responses/find_all_response.rb', line 13

def found(objects)
  garner.bind(cache_key(objects)) do
    present(key, objects).as_json
    present(:meta, pagination(objects)).as_json if paginated
  end
end

#invalid(exception) ⇒ Object



20
21
22
# File 'lib/hexagonal/responses/find_all_response.rb', line 20

def invalid(exception)
  error!({ errors: exception.record.errors }, 422)
end