aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-17 15:42:42 -0400
committerBryan Helmkamp <bryan@brynary.com>2009-05-17 15:42:42 -0400
commit8339f024c7663133a78c4d0a8824b5b6fafaf239 (patch)
treea43ebc9c956d8484647d81e5ea14534e7b0570a0 /lib/arel/algebra
parent4c71e3b2ea4b8da574954cbd8a26d12f2cc640d0 (diff)
downloadrails-8339f024c7663133a78c4d0a8824b5b6fafaf239.tar.gz
rails-8339f024c7663133a78c4d0a8824b5b6fafaf239.tar.bz2
rails-8339f024c7663133a78c4d0a8824b5b6fafaf239.zip
recursive memory operations now possible
Conflicts: lib/arel/algebra/relations/relation.rb
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r--lib/arel/algebra/extensions/hash.rb7
-rw-r--r--lib/arel/algebra/relations.rb1
-rw-r--r--lib/arel/algebra/relations/relation.rb4
-rw-r--r--lib/arel/algebra/relations/row.rb21
4 files changed, 22 insertions, 11 deletions
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