module Babik::QuerySet::Condition

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

Public Class Methods

factory(model, filter) click to toggle source

Return the Disjunction or Conjunction according to what class the filters parameter is. @param model [ActiveRecord::Base] Model owner of this condition. @param filter [Array, Hash] if it is an Array, it would be a disjunction.

If a Hash, it would be a conjunction.

@raise [RuntimeError] if the class of filters is not an Array or a Hash.

# 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