Class: Workarea::Search::StorefrontSearch
- Inherits:
-
Object
- Object
- Workarea::Search::StorefrontSearch
show all
- Defined in:
- app/queries/workarea/search/storefront_search.rb,
app/queries/workarea/search/storefront_search/redirect.rb,
app/queries/workarea/search/storefront_search/response.rb,
app/queries/workarea/search/storefront_search/template.rb,
app/queries/workarea/search/storefront_search/middleware.rb,
app/queries/workarea/search/storefront_search/exact_matches.rb,
app/queries/workarea/search/storefront_search/product_multipass.rb,
app/queries/workarea/search/storefront_search/spelling_correction.rb,
app/queries/workarea/search/storefront_search/product_auto_redirect.rb
Defined Under Namespace
Modules: Middleware
Classes: ExactMatches, ProductAutoRedirect, ProductMultipass, Redirect, Response, SpellingCorrection, Template
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of StorefrontSearch.
6
7
8
9
|
# File 'app/queries/workarea/search/storefront_search.rb', line 6
def initialize(params)
@params = params
@used_middleware = []
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
4
5
6
|
# File 'app/queries/workarea/search/storefront_search.rb', line 4
def params
@params
end
|
Instance Method Details
#create_middleware_chain ⇒ Object
45
46
47
48
49
|
# File 'app/queries/workarea/search/storefront_search.rb', line 45
def create_middleware_chain
Workarea.config.storefront_search_middleware.map do |class_name|
class_name.constantize.new(params, customization)
end
end
|
#customization ⇒ Object
11
12
13
14
15
16
|
# File 'app/queries/workarea/search/storefront_search.rb', line 11
def customization
@customization ||= begin
match = Customization.find_by_query(params[:q].try(:strip).to_s)
match.active? ? match : Customization.new
end
end
|
#response ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/queries/workarea/search/storefront_search.rb', line 18
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
|
#used_middleware ⇒ Object
40
41
42
43
|
# File 'app/queries/workarea/search/storefront_search.rb', line 40
def used_middleware
response
@used_middleware
end
|