Class: Sparkql::ExpressionState
- Inherits:
-
Object
- Object
- Sparkql::ExpressionState
- Defined in:
- lib/sparkql/expression_state.rb
Overview
Custom fields need to add a table join to the customfieldsearch table when AND’d together, but not when they are OR’d or nested. This class maintains the state for all custom field expressions lets the parser know when to do either.
Instance Method Summary collapse
-
#initialize ⇒ ExpressionState
constructor
A new instance of ExpressionState.
- #needs_join? ⇒ Boolean
- #push(expression) ⇒ Object
Constructor Details
#initialize ⇒ ExpressionState
Returns a new instance of ExpressionState.
5 6 7 8 9 |
# File 'lib/sparkql/expression_state.rb', line 5 def initialize @expressions = { 0 => [] } @last_conjunction = "And" # always start with a join @block_group = 0 end |
Instance Method Details
#needs_join? ⇒ Boolean
18 19 20 |
# File 'lib/sparkql/expression_state.rb', line 18 def needs_join? @expressions[@block_group].size == 1 || %w[Not And].include?(@last_conjunction) end |
#push(expression) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/sparkql/expression_state.rb', line 11 def push(expression) @block_group = expression[:block_group] @expressions[@block_group] ||= [] @expressions[@block_group] << expression @last_conjunction = expression[:conjunction] end |