From 8339f024c7663133a78c4d0a8824b5b6fafaf239 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 17 May 2009 15:42:42 -0400 Subject: recursive memory operations now possible Conflicts: lib/arel/algebra/relations/relation.rb --- lib/arel/algebra/extensions/hash.rb | 7 ------- lib/arel/algebra/relations.rb | 1 + lib/arel/algebra/relations/relation.rb | 4 ---- lib/arel/algebra/relations/row.rb | 21 +++++++++++++++++++++ 4 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 lib/arel/algebra/relations/row.rb (limited to 'lib/arel/algebra') diff --git a/lib/arel/algebra/extensions/hash.rb b/lib/arel/algebra/extensions/hash.rb index bc97785e62..7472b5aa73 100644 --- a/lib/arel/algebra/extensions/hash.rb +++ b/lib/arel/algebra/extensions/hash.rb @@ -4,11 +4,4 @@ class Hash bound.merge(key.bind(relation) => value.bind(relation)) end end - - def slice(*attributes) - inject({}) do |cheese, (key, value)| - cheese[key] = value if attributes.include?(key) - cheese - end - end end \ No newline at end of file diff --git a/lib/arel/algebra/relations.rb b/lib/arel/algebra/relations.rb index b75a31e5e3..94df5938fe 100644 --- a/lib/arel/algebra/relations.rb +++ b/lib/arel/algebra/relations.rb @@ -2,6 +2,7 @@ require 'arel/algebra/relations/relation' require 'arel/algebra/relations/utilities/compound' require 'arel/algebra/relations/utilities/nil' require 'arel/algebra/relations/utilities/externalization' +require 'arel/algebra/relations/row' require 'arel/algebra/relations/writes' require 'arel/algebra/relations/operations/alias' require 'arel/algebra/relations/operations/group' diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 6d76e66638..fe8cab4b02 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -14,10 +14,6 @@ module Arel self end - def root - self - end - module Enumerable include ::Enumerable diff --git a/lib/arel/algebra/relations/row.rb b/lib/arel/algebra/relations/row.rb new file mode 100644 index 0000000000..2d63498452 --- /dev/null +++ b/lib/arel/algebra/relations/row.rb @@ -0,0 +1,21 @@ +module Arel + class Row + attributes :relation, :tuple + deriving :==, :initialize + + def [](attribute) + tuple[relation.position_of(attribute)] + end + + def slice(*attributes) + Row.new(relation, attributes.inject([]) do |cheese, attribute| + cheese << self[attribute] + cheese + end) + end + + def bind(relation) + Row.new(relation, tuple) + end + end +end \ No newline at end of file -- cgit v1.2.3