Class: Pragma::Operation::Index

Inherits:
Base
  • Object
show all
Defined in:
lib/pragma/operation/index.rb

Overview

Finds all records of the requested resource, authorizes them, paginates them and decorates them.

Instance Method Summary collapse

Instance Method Details

#include!(options) ⇒ Object



22
23
24
25
26
# File 'lib/pragma/operation/index.rb', line 22

def include!(options)
  options['model'] = AssociationIncluder
    .load_adaptor(options['model'])
    .include_associations(options['params'][:expand] || [])
end

#respond!(options) ⇒ Object



36
37
38
39
40
# File 'lib/pragma/operation/index.rb', line 36

def respond!(options, **)
  options['result.response'] = Response::Ok.new(
    entity: options['result.decorator.collection']
  )
end

#retrieve!(options) ⇒ Object



18
19
20
# File 'lib/pragma/operation/index.rb', line 18

def retrieve!(options)
  options['model'] = options['model.class'].all
end

#scope!(options, model:) ⇒ Object

TODO: Turn this into a macro.



29
30
31
32
33
34
# File 'lib/pragma/operation/index.rb', line 29

def scope!(options, model:, **)
  options['model'] = options['policy.default.scope.class'].new(
    options['policy.context'] || options['current_user'],
    model
  ).resolve
end