aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2017-07-21 09:41:07 -0400
committerSean Griffin <sean@seantheprogrammer.com>2017-07-21 09:41:07 -0400
commitecec50da1d709f9b442c88c2f53a8065e2ed6548 (patch)
treea17e078fd51f7d83c96b2243452e1d261ffd2b63 /lib/arel
parent7ca5c37f484edebd169e4136331500d4b5c31cbe (diff)
downloadrails-ecec50da1d709f9b442c88c2f53a8065e2ed6548.tar.gz
rails-ecec50da1d709f9b442c88c2f53a8065e2ed6548.tar.bz2
rails-ecec50da1d709f9b442c88c2f53a8065e2ed6548.zip
Add a collector to grab the bind values off the AST
Now that the bind values are being stored on the actual AST, we need a way to pull them off into the array that we were previously maintaining separately. This requires a full walk of the AST. This is an expensive operation, so I've also added a visitor for delegating to more than one visitor in a single pass.
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/collectors/bind.rb24
-rw-r--r--lib/arel/collectors/composite.rb32
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/arel/collectors/bind.rb b/lib/arel/collectors/bind.rb
new file mode 100644
index 0000000000..d816aed90d
--- /dev/null
+++ b/lib/arel/collectors/bind.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Arel
+ module Collectors
+ class Bind
+ def initialize
+ @binds = []
+ end
+
+ def << str
+ self
+ end
+
+ def add_bind bind
+ @binds << bind
+ self
+ end
+
+ def value
+ @binds
+ end
+ end
+ end
+end
diff --git a/lib/arel/collectors/composite.rb b/lib/arel/collectors/composite.rb
new file mode 100644
index 0000000000..4f6156fe27
--- /dev/null
+++ b/lib/arel/collectors/composite.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module Arel
+ module Collectors
+ class Composite
+ def initialize(left, right)
+ @left = left
+ @right = right
+ end
+
+ def << str
+ left << str
+ right << str
+ self
+ end
+
+ def add_bind bind, &block
+ left.add_bind bind, &block
+ right.add_bind bind, &block
+ self
+ end
+
+ def value
+ [left.value, right.value]
+ end
+
+ protected
+
+ attr_reader :left, :right
+ end
+ end
+end