diff options
author | Dimko <deemox@gmail.com> | 2012-09-18 12:27:33 +0400 |
---|---|---|
committer | Dimko <deemox@gmail.com> | 2012-09-18 12:27:33 +0400 |
commit | 112617766915b0068027b4ac809dad8129c88e81 (patch) | |
tree | 5bcd2b69e3f2c449bb608b79e7b4a7c45609eb8c | |
parent | e032dabdb2adb34e3db8cd35e9f58bc0536475c1 (diff) | |
download | rails-112617766915b0068027b4ac809dad8129c88e81.tar.gz rails-112617766915b0068027b4ac809dad8129c88e81.tar.bz2 rails-112617766915b0068027b4ac809dad8129c88e81.zip |
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 24c435ad1d..2894bea19c 100644 --- a/lib/arel/visitors/depth_first.rb +++ b/lib/arel/visitors/depth_first.rb @@ -161,6 +161,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 8a83ebf48e..9bf9f88d18 100644 --- a/lib/arel/visitors/dot.rb +++ b/lib/arel/visitors/dot.rb @@ -212,6 +212,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 a350daa3da..6dd652a709 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -477,6 +477,7 @@ key on UpdateManager using UpdateManager#key= def visit_Array o o.map { |x| visit x }.join(', ') end + alias :visit_Set :visit_Array def quote value, column = nil @connection.quote value, column diff --git a/test/visitors/test_depth_first.rb b/test/visitors/test_depth_first.rb index 05360ff6e8..38d12b487c 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 @@ -159,6 +160,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 1caedacd45..2164e68cb7 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 @@ -114,6 +115,10 @@ module Arel @visitor.accept({:a => 1}) end + it "should visit_Set" do + @visitor.accept Set.new([1, 2]) + end + it "should visit_BigDecimal" do @visitor.accept BigDecimal.new('2.14') end |