class ParamsReady::Query::GroupingOperator

Attributes

type[R]

Public Class Methods

instance(type) click to toggle source
# File lib/params_ready/query/grouping.rb, line 121
def self.instance(type)
  raise ParamsReadyError, "Unimplemented operator: #{type}" unless @instances.key? type
  @instances[type]
end

Private Class Methods

new(type) click to toggle source
# File lib/params_ready/query/grouping.rb, line 166
def initialize(type)
  @type = type
end

Public Instance Methods

==(other) click to toggle source
# File lib/params_ready/query/grouping.rb, line 149
def ==(other)
  return false unless other.class <= GroupingOperator
  type == other.type
end
arel_method() click to toggle source
# File lib/params_ready/query/grouping.rb, line 126
def arel_method
  case type
  when :and, :or then type
  else
    raise ParamsReadyError, "Unimplemented operator: #{type}"
  end
end
connect(a, b) click to toggle source
# File lib/params_ready/query/grouping.rb, line 143
def connect(a, b)
  return b if a.nil?
  return a if b.nil?
  a.send arel_method, b
end
test(record, predicates) click to toggle source
# File lib/params_ready/query/grouping.rb, line 154
def test(record, predicates)
  definite = predicates.map do |predicate|
    predicate.test(record)
  end.compact

  return nil if definite.empty?

  definite.send(test_method)
end
test_method() click to toggle source
# File lib/params_ready/query/grouping.rb, line 134
def test_method
  case type
  when :and then :all?
  when :or then :any?
  else
    raise ParamsReadyError, "Unimplemented operator: #{type}"
  end
end