diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-17 15:46:51 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-17 15:46:51 -0300 |
commit | 94a8b12943bcdd0c6ac2b820f1300ccd80de87b2 (patch) | |
tree | aee75d102e2d8b35e58b99b06f048219cf6b4fbc | |
parent | 46f94aca3f648cf9a350cbe829f8d155d9af8739 (diff) | |
parent | 112617766915b0068027b4ac809dad8129c88e81 (diff) | |
download | rails-94a8b12943bcdd0c6ac2b820f1300ccd80de87b2.tar.gz rails-94a8b12943bcdd0c6ac2b820f1300ccd80de87b2.tar.bz2 rails-94a8b12943bcdd0c6ac2b820f1300ccd80de87b2.zip |
Merge pull request #137 from dimko/visit_set
Added a visitor for Set objects
-rw-r--r-- | lib/arel/visitors/depth_first.rb | 1 | ||||
-rw-r--r-- | lib/arel/visitors/dot.rb | 1 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 1 | ||||
-rw-r--r-- | test/visitors/test_depth_first.rb | 8 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 5 |
5 files changed, 16 insertions, 0 deletions
diff --git a/lib/arel/visitors/depth_first.rb b/lib/arel/visitors/depth_first.rb index 4d2ecfa5e1..eab20ac831 100644 --- a/lib/arel/visitors/depth_first.rb +++ b/lib/arel/visitors/depth_first.rb @@ -164,6 +164,7 @@ module Arel def visit_Array o o.each { |i| visit i } end + alias :visit_Set :visit_Array def visit_Hash o o.each { |k,v| visit(k); visit(v) } diff --git a/lib/arel/visitors/dot.rb b/lib/arel/visitors/dot.rb index f0cefeabd7..12cce1e266 100644 --- a/lib/arel/visitors/dot.rb +++ b/lib/arel/visitors/dot.rb @@ -216,6 +216,7 @@ module Arel edge(i) { visit x } end end + alias :visit_Set :visit_Array def visit_edge o, method edge(method) { visit o.send(method) } diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index ca09373b64..095aa5279a 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -752,6 +752,7 @@ module Arel def visit_Array o, collector inject_join o, collector, ", " end + alias :visit_Set :visit_Array def quote value, column = nil return value if Arel::Nodes::SqlLiteral === value diff --git a/test/visitors/test_depth_first.rb b/test/visitors/test_depth_first.rb index baa8f64184..d50ea3e59a 100644 --- a/test/visitors/test_depth_first.rb +++ b/test/visitors/test_depth_first.rb @@ -1,4 +1,5 @@ require 'helper' +require 'set' module Arel module Visitors @@ -171,6 +172,13 @@ module Arel assert_equal [:a, :b, node, list], @collector.calls end + def test_set + node = Nodes::Or.new(:a, :b) + set = Set.new([node]) + @visitor.accept set + assert_equal [:a, :b, node, set], @collector.calls + end + def test_hash node = Nodes::Or.new(:a, :b) hash = { node => node } diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index c03d89cfef..d84142e27a 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -1,4 +1,5 @@ require 'helper' +require 'set' module Arel module Visitors @@ -228,6 +229,10 @@ module Arel compile(Nodes.build_quoted({:a => 1})) end + it "should visit_Set" do + @visitor.accept Set.new([1, 2]) + end + it "should visit_BigDecimal" do compile Nodes.build_quoted(BigDecimal.new('2.14')) end |