Module: Discerner::Methods::Models::SearchCombination
- Included in:
- SearchCombination
- Defined in:
- lib/discerner/methods/models/search_combination.rb
Class Method Summary collapse
Instance Method Summary collapse
- #disabled? ⇒ Boolean
-
#initialize(*args) ⇒ Object
Instance Methods.
- #validate_searches ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Method Details
#disabled? ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 |
#initialize(*args) ⇒ Object
Instance Methods
23 24 25 |
# File 'lib/discerner/methods/models/search_combination.rb', line 23 def initialize(*args) super(*args) end |
#validate_searches ⇒ Object
27 28 29 30 |
# 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 |