Sha256: 75467ccb69e236e0d76053acb0b156e8aca31b982ee5150ce1d049ce6349a40f

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

module Workarea
  module Search
    class StorefrontSearch
      attr_reader :params

      def initialize(params)
        @params = params
        @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

11 entries across 11 versions & 1 rubygems

Version Path
workarea-core-3.5.9 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.8 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.7 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.6 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.5 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.4 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.3 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.2 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.1 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.0 app/queries/workarea/search/storefront_search.rb
workarea-core-3.5.0.beta.1 app/queries/workarea/search/storefront_search.rb