Class: ActiveRecordExpressionEvaluator

Inherits:
ExpressionEvaluator show all
Defined in:
lib/providers/active_record/active_record_expression_evaluator.rb

Direct Known Subclasses

ArGroupByExpressionEvaluator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ExpressionEvaluator

#visit_float, #visit_stringcontent, #visit_symbol, #visit_unary

Constructor Details

#initialize(linq_exp) ⇒ ActiveRecordExpressionEvaluator

Returns a new instance of ActiveRecordExpressionEvaluator.



4
5
6
7
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 4

def initialize(linq_exp)
  @binding = linq_exp.binding
  @conditions = {}
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



3
4
5
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 3

def conditions
  @conditions
end

Instance Method Details

#visit_arg(node) ⇒ Object



26
27
28
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 26

def visit_arg(node)
  node.arg.visit(self)
end

#visit_argslist(node) ⇒ Object



9
10
11
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 9

def visit_argslist(node)
  node.first.visit(self)
end

#visit_array(node) ⇒ Object



40
41
42
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 40

def visit_array(node)
  node.value
end

#visit_binary(node) ⇒ Object



20
21
22
23
24
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 20

def visit_binary(node)
  right_val = node.right.visit(self)
  left_val = node.left.visit(self)
  @conditions[left_val] = right_val
end

#visit_call(node) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 33

def visit_call(node)
  call = node.identifier.to_sym
  return call unless call == :member?
  target = node.target.visit(self)
  argument = node.arguments.visit(self)
  @conditions[argument] = target
end

#visit_integer(node) ⇒ Object



16
17
18
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 16

def visit_integer(node)
  node.value
end

#visit_statements(node) ⇒ Object



44
45
46
47
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 44

def visit_statements(node)
  binary_exp = node.elements.first
  binary_exp.visit(self)
end

#visit_string(node) ⇒ Object



29
30
31
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 29

def visit_string(node)
  node.value
end

#visit_variable(node) ⇒ Object



12
13
14
# File 'lib/providers/active_record/active_record_expression_evaluator.rb', line 12

def visit_variable(node)
  @binding.eval(node.to_s)
end