module Discerner::Methods::Models::SearchCombination

Public Class Methods

included(base) click to toggle source
# File lib/discerner/methods/models/search_combination.rb, line 5
def self.included(base)
  base.send :include, SoftDelete
  base.send :include, Warning

  # Associations
  base.send :belongs_to, :operator, inverse_of: :search_combinations
  base.send :belongs_to, :search,   inverse_of: :search_combinations,  foreign_key: :search_id
  base.send :belongs_to, :combined_search, foreign_key: :combined_search_id, class_name: 'Discerner::Search'

  # Scopes
  base.send(:scope, :ordered_by_display_order, -> { base.order('discerner_search_combinations.display_order ASC') })

  # Validations
  base.send :validates_presence_of, :search, :combined_search
  base.send :validate, :validate_searches
end
new(*args) click to toggle source

Instance Methods

Calls superclass method
# File lib/discerner/methods/models/search_combination.rb, line 23
def initialize(*args)
  super(*args)
end

Public Instance Methods

disabled?() click to toggle source
# File lib/discerner/methods/models/search_combination.rb, line 32
def disabled?
  return false unless persisted?
  return true if deleted?
  if combined_search.deleted?
    warnings.add(:base, "Combined search has been deleted and has to be removed from the search")
    return true
  elsif combined_search.disabled?
    warnings.add(:base, "Combined search has been disabled and has to be removed from the search")
    return true
  end
  return false
end
validate_searches() click to toggle source
# File lib/discerner/methods/models/search_combination.rb, line 27
def validate_searches
  return if self.search_id.blank? || self.combined_search_id.blank?
  errors.add(:base,"Search cannot be combined with itself.") if self.search_id == self.combined_search_id
end