Class: Workarea::Search::StorefrontSearch::Response
- Inherits:
-
Object
- Object
- Workarea::Search::StorefrontSearch::Response
- Defined in:
- app/queries/workarea/search/storefront_search/response.rb
Defined Under Namespace
Classes: Trace
Instance Attribute Summary collapse
-
#customization ⇒ Object
Returns the value of attribute customization.
-
#message ⇒ Object
Returns the value of attribute message.
-
#params ⇒ Object
Returns the value of attribute params.
-
#query ⇒ Object
Returns the value of attribute query.
-
#redirect ⇒ Object
Returns the value of attribute redirect.
-
#template ⇒ Object
Returns the value of attribute template.
-
#trace ⇒ Object
Returns the value of attribute trace.
Instance Method Summary collapse
- #autoselected_filter?(name) ⇒ Boolean
- #has_filters? ⇒ Boolean
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
- #product_rules ⇒ Object
- #query_string ⇒ Object
- #query_suggestions ⇒ Object
- #redirect? ⇒ Boolean
-
#reset!(params, by: nil) ⇒ Object
Reset the parameters and resulting query to match the new parameters passed in.
- #total ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 10 def initialize( = {}) @template = .fetch(:template, 'show') @message = [:message] @redirect = [:redirect] @params = .fetch(:params, {}) @params[:terms_facets] = terms_facets @params[:range_facets] = Settings.current.range_facets @original_params = @params.deep_dup @customization = [:customization] @trace = [] reset!(@params) end |
Instance Attribute Details
#customization ⇒ Object
Returns the value of attribute customization.
7 8 9 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7 def customization @customization end |
#message ⇒ Object
Returns the value of attribute message.
7 8 9 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7 def @message end |
#params ⇒ Object
Returns the value of attribute params.
7 8 9 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7 def params @params end |
#query ⇒ Object
Returns the value of attribute query.
7 8 9 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7 def query @query end |
#redirect ⇒ Object
Returns the value of attribute redirect.
7 8 9 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7 def redirect @redirect end |
#template ⇒ Object
Returns the value of attribute template.
7 8 9 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7 def template @template end |
#trace ⇒ Object
Returns the value of attribute trace.
7 8 9 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 7 def trace @trace end |
Instance Method Details
#autoselected_filter?(name) ⇒ Boolean
49 50 51 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 49 def autoselected_filter?(name) params[name].present? && @original_params[name].blank? end |
#has_filters? ⇒ Boolean
45 46 47 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 45 def has_filters? query.facets.any?(&:selected?) end |
#product_rules ⇒ Object
61 62 63 64 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 61 def product_rules return [] if customization.blank? customization.product_rules.usable end |
#query_string ⇒ Object
41 42 43 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 41 def query_string params[:q].strip end |
#query_suggestions ⇒ Object
57 58 59 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 57 def query_suggestions @query.query_suggestions end |
#redirect? ⇒ Boolean
26 27 28 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 26 def redirect? @redirect.present? end |
#reset!(params, by: nil) ⇒ Object
Reset the parameters and resulting query to match the new parameters passed in. Used when correcting spelling, or auto filtering results.
35 36 37 38 39 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 35 def reset!(params, by: nil) @params = params @query = Search::ProductSearch.new(params.merge(rules: product_rules)) @trace << Trace.new(@params, @query, by) end |
#total ⇒ Object
53 54 55 |
# File 'app/queries/workarea/search/storefront_search/response.rb', line 53 def total query.total end |