module CanCanCan::BabySqueel::ExpressionCombinator
Constants
- ALWAYS_FALSE
This true expression is used to indicate a condition that is never satisfied.
- ALWAYS_TRUE
This true expression is used to indicate a condition that is always satisfied.
Public Instance Methods
Combines two Squeel expressions. This is aware of the ALWAYS_TRUE
and ALWAYS_FALSE
constants and performs simplification.
@param [Squeel::Nodes::Node] left_expression The left expression. @param [Array] left_expression_joins An array of joins which the Squeel expression must be
joined to.
@param [Symbol] operator The operator to combine with. This must be either :and
or :or
. @param [Squeel::Nodes::Node] right_expression The right expression. @param [Array] right_expression_joins An array of joins which the Squeel expression must be
joined to.
@return [Array<(Squeel::Nodes::Node, Array)>] A tuple containing the combination of the given
expressions, as well as an array of joins which the Squeel expression must be joined to.
# File lib/cancancan/baby_squeel/expression_combinator.rb, line 21 def combine_squeel_expressions(left_expression, left_expression_joins, operator, right_expression, right_expression_joins) case operator when :and then conjunction_expressions(left_expression, left_expression_joins, right_expression, right_expression_joins) when :or then disjunction_expressions(left_expression, left_expression_joins, right_expression, right_expression_joins) else raise ArgumentError, "#{operator} must either be :and or :or" end end
Computes the conjunction of the two Squeel expressions.
Boolean simplification is done for the ALWAYS_TRUE
and ALWAYS_FALSE
values. @param [Squeel::Nodes::Node] left_expression The left expression. @param [Array] left_expression_joins An array of joins which the Squeel expression must be
joined to.
@param [Squeel::Nodes::Node] right_expression The right expression. @param [Array] right_expression_joins An array of joins which the Squeel expression must be
joined to.
@return [Array<(Squeel::Nodes::Node, Array)>] A tuple containing the conjunction of the left and
right expressions, as well as an array of joins which the Squeel expression must be joined to.
# File lib/cancancan/baby_squeel/expression_combinator.rb, line 44 def conjunction_expressions(left_expression, left_expression_joins, right_expression, right_expression_joins) if left_expression == ALWAYS_FALSE || right_expression == ALWAYS_FALSE [ALWAYS_FALSE, []] elsif left_expression == ALWAYS_TRUE [right_expression, right_expression_joins] elsif right_expression == ALWAYS_TRUE [left_expression, left_expression_joins] else [left_expression.and(right_expression), left_expression_joins + right_expression_joins] end end
Computes the disjunction of the two Squeel expressions.
Boolean simplification is done for the ALWAYS_TRUE
and ALWAYS_FALSE
values. @param [Squeel::Nodes::Node] left_expression The left expression. @param [Array] left_expression_joins An array of joins which the Squeel expression must be
joined to.
@param [Squeel::Nodes::Node] right_expression The right expression. @param [Array] right_expression_joins An array of joins which the Squeel expression must be
joined to.
@return [Array<(Squeel::Nodes::Node, Array)>] A tuple containing the disjunction of the left and
right expressions, as well as an array of joins which the Squeel expression must be joined to.
# File lib/cancancan/baby_squeel/expression_combinator.rb, line 68 def disjunction_expressions(left_expression, left_expression_joins, right_expression, right_expression_joins) if left_expression == ALWAYS_TRUE || right_expression == ALWAYS_TRUE [ALWAYS_TRUE, []] elsif left_expression == ALWAYS_FALSE [right_expression, right_expression_joins] elsif right_expression == ALWAYS_FALSE [left_expression, left_expression_joins] else [left_expression.or(right_expression), left_expression_joins + right_expression_joins] end end