Sha256: 8788b72cdb9e9d55a2439723bb95f3ff7d044946f6aaa55b351fc43222b95b8e

Contents?: true

Size: 1.24 KB

Versions: 17

Compression:

Stored size: 1.24 KB

Contents

module Workarea
  module Search
    class StorefrontSearch
      attr_reader :params

      def initialize(params)
        @params = params.with_indifferent_access.except(:per_page)
        @used_middleware = []
      end

      def customization
        @customization ||= begin
          match = Customization.find_by_query(params[:q].try(:strip).to_s)
          match.active? ? match : Customization.new
        end
      end

      def response
        @response ||=
          begin
            result = StorefrontSearch::Response.new(
              params: params,
              customization: customization
            )
            chain = create_middleware_chain

            traverse_chain = lambda do
              unless chain.empty?
                piece = chain.shift
                @used_middleware << piece
                piece.call(result, &traverse_chain)
              end
            end

            traverse_chain.call
            result
          end
      end

      def used_middleware
        response
        @used_middleware
      end

      def create_middleware_chain
        Workarea.config.storefront_search_middleware.map do |class_name|
          class_name.constantize.new(params, customization)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.26 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.25 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.23 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.22 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.21 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.20 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.19 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.18 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.17 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.16 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.15 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.14 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.13 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.12 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.11 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.10 app/queries/workarea/search/storefront_search.rb