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.

Author:

  • Alessandro Desantis

Instance Method Summary collapse

Instance Method Details

#respond!(options) ⇒ Object



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

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

#retrieve!(options) ⇒ Object



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

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

#scope!(options, model:) ⇒ Object

TODO: Turn this into a macro.



24
25
26
27
28
29
# File 'lib/pragma/operation/index.rb', line 24

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