Class: Workarea::Search::Customization

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument, Commentable, Contentable, FeaturedProducts, ProductList, Releasable
Defined in:
app/models/workarea/search/customization.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FeaturedProducts

#add_product, changesets, #featured_product?, #featured_products?, #remove_product

Methods included from Commentable

#add_subscription, #remove_subscription

Methods included from Releasable

#changesets_with_children, #destroy, #in_release, #release_changes, #release_originals, #save_changeset, #skip_changeset, #without_release

Methods included from Workarea::Segmentable

#active?, #active_segment_ids_with_children, #segmented?, #segments

Methods included from Release::Activation

#activate_with?, #create_activation_changeset, #save_activate_with, #was_active?

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#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

.sortsObject



42
43
44
# File 'app/models/workarea/search/customization.rb', line 42

def self.sorts
  [Workarea::Sort.newest, Workarea::Sort.query]
end

Instance Method Details

#not_star_queryObject



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

#redirectObject



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

Returns:

  • (Boolean)


70
71
72
# File 'app/models/workarea/search/customization.rb', line 70

def redirect?
  redirect.present?
end

#rewrite?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/workarea/search/customization.rb', line 66

def rewrite?
  rewrite.present?
end