diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-21 08:33:09 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-21 08:33:09 -0400 |
commit | db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0 (patch) | |
tree | f0f7623e9b730679adcb0dfe97f9c8415a91328f /lib/arel/visitors | |
parent | f031a3b9aa6a8093802e0188abce58e0b997078e (diff) | |
download | rails-db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0.tar.gz rails-db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0.tar.bz2 rails-db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0.zip |
Add a value field `Nodes::BindParam`
This is part of a greater refactoring to have the `BindParam` nodes hold
onto their values. We want to generally keep the AST decoupled from what
you're actually doing with those values, but ultimately the usage of
`BindParam` is almost identical to how you'd use `Casted` or `Quoted`.
Forcing consumers of Arel's API to maintain the bind values separately
from the AST makes manipulating the AST essentially impossible, as you
would need to perform a full walk of the AST to determine whether a
given node contains bind parameters, and which value it maps to.
By storing the value on the bind parameter directly, we can collect them
in another AST pass (realistically it'll be part of the same pass that
performs SQL construction for performance reasons). This will
dramatically simplify AST manipulation for Rails or any other consumers
that work with bind params.
As part of this change I've removed the `BindVisitor`, which appears to
be dead code, and had tests break from this change.
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/bind_visitor.rb | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/lib/arel/visitors/bind_visitor.rb b/lib/arel/visitors/bind_visitor.rb deleted file mode 100644 index 8a5570cf5c..0000000000 --- a/lib/arel/visitors/bind_visitor.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true -module Arel - module Visitors - module BindVisitor - def initialize target - @block = nil - super - end - - def accept node, collector, &block - @block = block if block_given? - super - end - - private - - def visit_Arel_Nodes_Assignment o, collector - if o.right.is_a? Arel::Nodes::BindParam - collector = visit o.left, collector - collector << " = " - visit o.right, collector - else - super - end - end - - def visit_Arel_Nodes_BindParam o, collector - if @block - val = @block.call - if String === val - collector << val - end - else - super - end - end - - end - end -end |