From 9d77c08cf8a75636b058c1b85af52ef96e07cee5 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 17 May 2009 15:00:10 -0400 Subject: made block stuff read nicer Conflicts: doc/TODO --- lib/arel/algebra/relations/operations/group.rb | 3 ++- lib/arel/algebra/relations/operations/order.rb | 3 ++- lib/arel/algebra/relations/operations/project.rb | 3 ++- lib/arel/algebra/relations/utilities/compound.rb | 5 +++++ 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/arel') diff --git a/lib/arel/algebra/relations/operations/group.rb b/lib/arel/algebra/relations/operations/group.rb index 04fd9fea62..879f2352c5 100644 --- a/lib/arel/algebra/relations/operations/group.rb +++ b/lib/arel/algebra/relations/operations/group.rb @@ -5,7 +5,8 @@ module Arel def initialize(relation, *groupings, &block) @relation = relation - @groupings = (groupings + (block_given?? [yield(relatoin)] : [])).collect { |g| g.bind(relation) } + @groupings = (groupings + arguments_from_block(relation, &block)) \ + .collect { |g| g.bind(relation) } end def externalizable? diff --git a/lib/arel/algebra/relations/operations/order.rb b/lib/arel/algebra/relations/operations/order.rb index eccd8bcda0..4e7133f5a8 100644 --- a/lib/arel/algebra/relations/operations/order.rb +++ b/lib/arel/algebra/relations/operations/order.rb @@ -5,7 +5,8 @@ module Arel def initialize(relation, *orderings, &block) @relation = relation - @orderings = (orderings + (block_given?? [yield(relation)] : [])).collect { |o| o.bind(relation) } + @orderings = (orderings + arguments_from_block(relation, &block)) \ + .collect { |o| o.bind(relation) } end # TESTME diff --git a/lib/arel/algebra/relations/operations/project.rb b/lib/arel/algebra/relations/operations/project.rb index 5507ea3163..223d320e22 100644 --- a/lib/arel/algebra/relations/operations/project.rb +++ b/lib/arel/algebra/relations/operations/project.rb @@ -5,7 +5,8 @@ module Arel def initialize(relation, *projections, &block) @relation = relation - @projections = (projections + (block_given?? [yield(relation)] : [])).collect { |p| p.bind(relation) } + @projections = (projections + arguments_from_block(relation, &block)) \ + .collect { |p| p.bind(relation) } end def attributes diff --git a/lib/arel/algebra/relations/utilities/compound.rb b/lib/arel/algebra/relations/utilities/compound.rb index 4d7cece812..99c3d02748 100644 --- a/lib/arel/algebra/relations/utilities/compound.rb +++ b/lib/arel/algebra/relations/utilities/compound.rb @@ -13,5 +13,10 @@ module Arel end OPERATION end + + private + def arguments_from_block(relation, &block) + block_given?? [yield(relation)] : [] + end end end -- cgit v1.2.3