aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/engines/memory
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/engines/memory')
-rw-r--r--lib/arel/engines/memory/predicates.rb6
-rw-r--r--lib/arel/engines/memory/relations.rb1
-rw-r--r--lib/arel/engines/memory/relations/array.rb2
-rw-r--r--lib/arel/engines/memory/relations/compound.rb4
-rw-r--r--lib/arel/engines/memory/relations/operations.rb10
-rw-r--r--lib/arel/engines/memory/relations/relation.rb7
6 files changed, 24 insertions, 6 deletions
diff --git a/lib/arel/engines/memory/predicates.rb b/lib/arel/engines/memory/predicates.rb
index bbf39ba794..e233f3ba39 100644
--- a/lib/arel/engines/memory/predicates.rb
+++ b/lib/arel/engines/memory/predicates.rb
@@ -21,15 +21,19 @@ module Arel
end
class Equality < Binary
+ def operator; :== end
end
class GreaterThanOrEqualTo < Binary
+ def operator; :>= end
end
class GreaterThan < Binary
+ def operator; :> end
end
class LessThanOrEqualTo < Binary
+ def operator; :<= end
end
class LessThan < Binary
@@ -37,8 +41,10 @@ module Arel
end
class Match < Binary
+ def operator; :=~ end
end
class In < Binary
+ def operator; :include? end
end
end
diff --git a/lib/arel/engines/memory/relations.rb b/lib/arel/engines/memory/relations.rb
index 1b009537b9..820b0af4b2 100644
--- a/lib/arel/engines/memory/relations.rb
+++ b/lib/arel/engines/memory/relations.rb
@@ -1,3 +1,4 @@
+require 'arel/engines/memory/relations/relation'
require 'arel/engines/memory/relations/array'
require 'arel/engines/memory/relations/operations'
require 'arel/engines/memory/relations/compound'
diff --git a/lib/arel/engines/memory/relations/array.rb b/lib/arel/engines/memory/relations/array.rb
index c02c62891b..ea0b5af5ba 100644
--- a/lib/arel/engines/memory/relations/array.rb
+++ b/lib/arel/engines/memory/relations/array.rb
@@ -15,7 +15,7 @@ module Arel
end
def eval
- @array.collect { |row| attributes.zip(row).to_hash }
+ @array.collect { |r| Row.new(self, r) }
end
end
end \ No newline at end of file
diff --git a/lib/arel/engines/memory/relations/compound.rb b/lib/arel/engines/memory/relations/compound.rb
index b029082d57..3791fa4622 100644
--- a/lib/arel/engines/memory/relations/compound.rb
+++ b/lib/arel/engines/memory/relations/compound.rb
@@ -1,5 +1,9 @@
module Arel
class Compound < Relation
delegate :array, :to => :relation
+
+ def unoperated_rows
+ relation.eval.collect { |row| row.bind(self) }
+ end
end
end
diff --git a/lib/arel/engines/memory/relations/operations.rb b/lib/arel/engines/memory/relations/operations.rb
index 115df054df..8e03aca7b1 100644
--- a/lib/arel/engines/memory/relations/operations.rb
+++ b/lib/arel/engines/memory/relations/operations.rb
@@ -1,13 +1,13 @@
module Arel
class Where < Compound
def eval
- relation.eval.select { |row| predicate.eval(row) }
+ unoperated_rows.select { |row| predicate.eval(row) }
end
end
class Order < Compound
def eval
- relation.eval.sort do |row1, row2|
+ unoperated_rows.sort do |row1, row2|
ordering = orderings.detect { |o| o.eval(row1, row2) != 0 } || orderings.last
ordering.eval(row1, row2)
end
@@ -16,19 +16,19 @@ module Arel
class Project < Compound
def eval
- relation.eval.collect { |r| r.slice(*projections) }
+ unoperated_rows.collect { |r| r.slice(*projections) }
end
end
class Take < Compound
def eval
- relation.eval[0, taken]
+ unoperated_rows[0, taken]
end
end
class Skip < Compound
def eval
- relation.eval[skipped..-1]
+ unoperated_rows[skipped..-1]
end
end
diff --git a/lib/arel/engines/memory/relations/relation.rb b/lib/arel/engines/memory/relations/relation.rb
new file mode 100644
index 0000000000..abfb8bb37f
--- /dev/null
+++ b/lib/arel/engines/memory/relations/relation.rb
@@ -0,0 +1,7 @@
+module Arel
+ class Relation
+ def position_of(attribute)
+ attributes.index(self[attribute])
+ end
+ end
+end \ No newline at end of file