Sha256: d172e1499e4563a065aad68d82b44131d0798374df4caf365e922ee215855fff

Contents?: true

Size: 921 Bytes

Versions: 2

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true

module Pragma
  module Operation
    # Finds all records of the requested resource, authorizes them, paginates them and decorates
    # them.
    #
    # @author Alessandro Desantis
    class Index < Pragma::Operation::Base
      step Macro::Classes()
      step :retrieve!
      step :scope!
      step Macro::Filtering()
      step Macro::Ordering()
      step Macro::Pagination()
      step Macro::Decorator(name: :collection)
      step :respond!

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pragma-2.1.1 lib/pragma/operation/index.rb
pragma-2.1.0 lib/pragma/operation/index.rb