Module: Mincer::Processors::Helpers

Included in:
Mincer::PgSearch::SearchEngines::Base, PgSearch::Processor
Defined in:
lib/mincer/processors/helpers.rb

Instance Method Summary collapse

Instance Method Details

#join_expressions(expressions, join_with) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/mincer/processors/helpers.rb', line 5

def join_expressions(expressions, join_with)
  return expressions.first if expressions.size < 2
  case join_with
  when :and then Arel::Nodes::And.new(expressions)
  when :or then expressions.inject { |accumulator, expression| Arel::Nodes::Or.new(accumulator, expression) }
  else expressions.inject { |accumulator, expression| Arel::Nodes::InfixOperation.new(join_with, accumulator, expression) }
  end
end