Sha256: 98b31d3fae4f588e6ca9c80219ef00bc6ad4c9ceec9ff4d1bcb07e4d2841713a

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

# frozen_string_literal: true

require 'active_support/concern'
require_relative './change_context_concern'

module SnFoil
  module Contexts
    module IndexContextConcern
      extend ActiveSupport::Concern

      included do
        include SetupContextConcern
      end

      class_methods do
        attr_reader :i_searcher

        def index(params: {}, user: nil, **options)
          new(user).index(**options, params: params)
        end

        def searcher(klass = nil)
          @i_searcher = klass
        end
      end

      def searcher
        self.class.i_searcher
      end

      def index(params:, **options)
        options[:action] = :index
        options = setup_index(**options)
        options.fetch(:searcher) { searcher }
               .new(scope: scope.resolve)
               .search(params: params)
      end

      # Param manipulation based on User should be done here
      def setup_index(**options)
        options
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snfoil-0.1.0 lib/sn_foil/contexts/index_context_concern.rb