From ecec50da1d709f9b442c88c2f53a8065e2ed6548 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 21 Jul 2017 09:41:07 -0400 Subject: 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. --- lib/arel/collectors/bind.rb | 24 ++++++++++++++++++++++++ lib/arel/collectors/composite.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 lib/arel/collectors/bind.rb create mode 100644 lib/arel/collectors/composite.rb (limited to 'lib') 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 -- cgit v1.2.3