Class: Workarea::Search::Customization
Class Method Summary
collapse
Instance Method Summary
collapse
#add_product, changesets, #featured_product?, #featured_products?, #remove_product
#add_subscription, #remove_subscription
Methods included from Releasable
#changesets_with_children, #destroy, #in_release, #release_changes, #release_originals, #save_changeset, #skip_changeset, #without_release
#active?, #active_segment_ids_with_children, #segmented?, #segments
#activate_with?, #create_activation_changeset, #save_activate_with, #was_active?
#releasable?
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
#embedded_children
Class Method Details
.autocomplete(string) ⇒ Object
24
25
26
27
|
# File 'app/models/workarea/search/customization.rb', line 24
def self.autocomplete(string)
regex = /^#{::Regexp.quote(string)}/
where(query: regex).pluck(:query)
end
|
.find_by_query(query) ⇒ Object
29
30
31
32
33
|
# File 'app/models/workarea/search/customization.rb', line 29
def self.find_by_query(query)
result = find_or_initialize_by(id: QueryString.new(query).id)
result.query ||= query
result
end
|
.positions_for_product(id) ⇒ Object
35
36
37
38
39
40
|
# File 'app/models/workarea/search/customization.rb', line 35
def self.positions_for_product(id)
self.in(product_ids: Array(id)).reduce({}) do |memo, sort|
memo[sort.id] = sort.product_ids.index(id.to_s)
memo
end
end
|
Instance Method Details
#not_star_query ⇒ Object
74
75
76
77
78
|
# File 'app/models/workarea/search/customization.rb', line 74
def not_star_query
if query.to_s.strip == '*'
errors.add(:query, I18n.t('workarea.errors.messages.not_star_query'))
end
end
|
#query=(value) ⇒ Object
46
47
48
|
# File 'app/models/workarea/search/customization.rb', line 46
def query=(value)
super(value.downcase)
end
|
#redirect ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/models/workarea/search/customization.rb', line 50
def redirect
value = read_attribute(:redirect)
return unless value.present?
return value if UrlValidator.valid_url?(value)
case value
when /\A\//
value
when /[\.{2,}]/
"http://#{value}"
else
"/#{value}"
end
end
|
#redirect? ⇒ Boolean
70
71
72
|
# File 'app/models/workarea/search/customization.rb', line 70
def redirect?
redirect.present?
end
|
#rewrite? ⇒ Boolean
66
67
68
|
# File 'app/models/workarea/search/customization.rb', line 66
def rewrite?
rewrite.present?
end
|