Class: PgExecArrayParams::Rewriters::ResTarget
- Inherits:
-
Node
- Object
- Node
- PgExecArrayParams::Rewriters::ResTarget
show all
- Defined in:
- lib/pg_exec_array_params/rewriters/res_target.rb
Constant Summary
collapse
- VAL =
'val'
Instance Attribute Summary
Attributes inherited from Node
#ref_idx, #value
Instance Method Summary
collapse
Methods inherited from Node
#initialize, #process, #to_s
Instance Method Details
#plain_selection? ⇒ Boolean
handle “select $1” “location”=>7}, “location”=>7} AExpr handles “select $1 + 1”
33
34
35
|
# File 'lib/pg_exec_array_params/rewriters/res_target.rb', line 33
def plain_selection?
value.key?(VAL) && value[VAL].is_a?(Hash) && value[VAL].key?(PARAM_REF)
end
|
#rewrite! ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/pg_exec_array_params/rewriters/res_target.rb', line 12
def rewrite!
old_ref_idx = value[VAL][PARAM_REF][NUMBER] - 1 unless (new_ref_idx = ref_idx[old_ref_idx])
raise Error.new("No parameter for $#{old_ref_idx + 1}", nil, self)
end
if new_ref_idx.is_a?(Array)
elements = Range.new(*new_ref_idx).map do |param_ref_idx|
{ PARAM_REF => { NUMBER => param_ref_idx } }
end
value[VAL] = { 'A_ArrayExpr' => { 'elements' => elements } }
else
value[VAL][PARAM_REF][NUMBER] = new_ref_idx
end
end
|
#should_rewrite? ⇒ Boolean
8
9
10
|
# File 'lib/pg_exec_array_params/rewriters/res_target.rb', line 8
def should_rewrite?
plain_selection?
end
|