Class: DataMapper::Ambition::Query::FilterProcessor

Inherits:
SexpProcessor
  • Object
show all
Defined in:
lib/dm-ambition/query/filter_processor.rb

Constant Summary collapse

SEND_METHODS =
[ :send, :__send__ ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binding, model) ⇒ FilterProcessor

Returns a new instance of FilterProcessor.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dm-ambition/query/filter_processor.rb', line 9

def initialize(binding, model)
  super()

  self.expected        = Object # allow anything for now
  self.auto_shift_type = true
  self.default_method  = :process_error

  @binding = binding
  @model   = model

  @conditions = @container = DataMapper::Query::Conditions::Operation.new(:and)
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



5
6
7
# File 'lib/dm-ambition/query/filter_processor.rb', line 5

def conditions
  @conditions
end

Instance Method Details

#process_and(exp) ⇒ Object



48
49
50
# File 'lib/dm-ambition/query/filter_processor.rb', line 48

def process_and(exp)
  process_connective(exp, :and)
end

#process_arglist(exp) ⇒ Object



65
66
67
# File 'lib/dm-ambition/query/filter_processor.rb', line 65

def process_arglist(exp)
  process_array(exp)
end

#process_array(exp) ⇒ Object



125
126
127
128
129
# File 'lib/dm-ambition/query/filter_processor.rb', line 125

def process_array(exp)
  array = []
  array << process(exp.shift) until exp.empty?
  array
end

#process_block(exp) ⇒ Object



69
70
71
# File 'lib/dm-ambition/query/filter_processor.rb', line 69

def process_block(exp)
  process_array(exp).last
end

#process_call(exp) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dm-ambition/query/filter_processor.rb', line 32

def process_call(exp)
  lhs      = process(exp.shift)
  operator = exp.shift
  rhs      = process(exp.shift)

  while SEND_METHODS.include?(operator)
    operator = rhs.shift
  end

  if lhs.nil? && operator != :==
    call_method(operator, *rhs)
  else
    evaluate_operator(operator, lhs, rhs.shift)
  end
end

#process_colon2(exp) ⇒ Object



77
78
79
# File 'lib/dm-ambition/query/filter_processor.rb', line 77

def process_colon2(exp)
  process(exp.shift).const_get(exp.shift)
end

#process_const(exp) ⇒ Object



81
82
83
# File 'lib/dm-ambition/query/filter_processor.rb', line 81

def process_const(exp)
  Object.const_get(exp.shift)
end

#process_error(exp) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
# File 'lib/dm-ambition/query/filter_processor.rb', line 22

def process_error(exp)
  raise ArgumentError, "calling process_#{exp.shift} with #{exp.inspect}"
end

#process_false(exp) ⇒ Object



117
118
119
# File 'lib/dm-ambition/query/filter_processor.rb', line 117

def process_false(exp)
  false
end

#process_gvar(exp) ⇒ Object



109
110
111
# File 'lib/dm-ambition/query/filter_processor.rb', line 109

def process_gvar(exp)
  eval(exp.shift)
end

#process_hash(exp) ⇒ Object



131
132
133
134
135
# File 'lib/dm-ambition/query/filter_processor.rb', line 131

def process_hash(exp)
  hash = {}
  hash[process(exp.shift)] = process(exp.shift) until exp.empty?
  hash
end

#process_iter(exp) ⇒ Object



26
27
28
29
30
# File 'lib/dm-ambition/query/filter_processor.rb', line 26

def process_iter(exp)
  exp.shift
  @receiver = process(exp.shift)
  process(exp.shift)
end

#process_ivar(exp) ⇒ Object



105
106
107
# File 'lib/dm-ambition/query/filter_processor.rb', line 105

def process_ivar(exp)
  eval(exp.shift)
end

#process_lasgn(exp) ⇒ Object



91
92
93
94
95
# File 'lib/dm-ambition/query/filter_processor.rb', line 91

def process_lasgn(exp)
  var = exp.shift
  return var if exp.empty?
  assign_value(var, process(exp.shift))
end

#process_lit(exp) ⇒ Object



101
102
103
# File 'lib/dm-ambition/query/filter_processor.rb', line 101

def process_lit(exp)
  exp.shift
end

#process_lvar(exp) ⇒ Object



60
61
62
63
# File 'lib/dm-ambition/query/filter_processor.rb', line 60

def process_lvar(exp)
  lvar = exp.shift
  lvar.equal?(@receiver) ? @receiver : eval(lvar)
end

#process_masgn(exp) ⇒ Object



85
86
87
88
89
# File 'lib/dm-ambition/query/filter_processor.rb', line 85

def process_masgn(exp)
  vars, values = process(exp.shift), process(exp.shift)
  vars.zip(values) { |var, value| assign_value(var, value) }
  values
end

#process_match3(exp) ⇒ Object



73
74
75
# File 'lib/dm-ambition/query/filter_processor.rb', line 73

def process_match3(exp)
  evaluate_operator(:=~, process(exp.shift), process(exp.shift))
end

#process_nil(exp) ⇒ Object



121
122
123
# File 'lib/dm-ambition/query/filter_processor.rb', line 121

def process_nil(exp)
  nil
end

#process_not(exp) ⇒ Object



56
57
58
# File 'lib/dm-ambition/query/filter_processor.rb', line 56

def process_not(exp)
  process_connective(exp, :not)
end

#process_or(exp) ⇒ Object



52
53
54
# File 'lib/dm-ambition/query/filter_processor.rb', line 52

def process_or(exp)
  process_connective(exp, :or)
end

#process_str(exp) ⇒ Object



97
98
99
# File 'lib/dm-ambition/query/filter_processor.rb', line 97

def process_str(exp)
  exp.shift
end

#process_true(exp) ⇒ Object



113
114
115
# File 'lib/dm-ambition/query/filter_processor.rb', line 113

def process_true(exp)
  true
end