Sha256: 3aa58f74eb9deaa950dbfdb7c03144f49f326644ef6c256beecfdd6f31c6a7d6

Contents?: true

Size: 1.14 KB

Versions: 20

Compression:

Stored size: 1.14 KB

Contents

module Workarea
  module Search
    class StorefrontSearch
      attr_reader :params

      def initialize(params)
        @params = params
        @used_middleware = []
      end

      def customization
        @customization ||= Customization.active.find_by_query(
          params[:q].try(:strip).to_s
        )
      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

20 entries across 20 versions & 1 rubygems

Version Path
workarea-core-3.4.31 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.30 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.29 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.28 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.27 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.26 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.25 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.24 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.23 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.22 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.21 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.20 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.19 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.18 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.17 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.16 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.15 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.14 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.13 app/queries/workarea/search/storefront_search.rb
workarea-core-3.4.12 app/queries/workarea/search/storefront_search.rb