Module: Babik::QuerySet::Condition

Defined in:
lib/babik/queryset/lib/condition.rb

Overview

Each one of the conditions that can appear in a SQL WHERE.

Defined Under Namespace

Classes: Conjunction

Class Method Summary collapse

Class Method Details

.factory(model, filter) ⇒ Object

Return the Disjunction or Conjunction according to what class the filters parameter is.

Parameters:

  • model (ActiveRecord::Base)

    Model owner of this condition.

  • filter (Array, Hash)

    if it is an Array, it would be a disjunction. If a Hash, it would be a conjunction.

Raises:

  • (RuntimeError)

    if the class of filters is not an Array or a Hash.



13
14
15
16
17
18
19
20
21
# File 'lib/babik/queryset/lib/condition.rb', line 13

def self.factory(model, filter)
  if filter.class == Array
    return Disjunction.new(model, filter.map { |filter_i| Conjunction.new(model, filter_i) })
  end
  if filter.class == Hash
    return Conjunction.new(model, filter)
  end
  raise '`filter\' parameter must be an Array for OR-based AND-conditions or a hash for a lone AND-condition'
end