aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/engines/memory/relations/operations.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/engines/memory/relations/operations.rb')
-rw-r--r--lib/arel/engines/memory/relations/operations.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/arel/engines/memory/relations/operations.rb b/lib/arel/engines/memory/relations/operations.rb
new file mode 100644
index 0000000000..8e01938360
--- /dev/null
+++ b/lib/arel/engines/memory/relations/operations.rb
@@ -0,0 +1,61 @@
+module Arel
+ class Where < Compound
+ def eval
+ unoperated_rows.select { |row| predicate.eval(row) }
+ end
+ end
+
+ class Order < Compound
+ def eval
+ unoperated_rows.sort do |row1, row2|
+ ordering = orderings.detect { |o| o.eval(row1, row2) != 0 } || orderings.last
+ ordering.eval(row1, row2)
+ end
+ end
+ end
+
+ class Project < Compound
+ def eval
+ unoperated_rows.collect { |r| r.slice(*projections) }
+ end
+ end
+
+ class Take < Compound
+ def eval
+ unoperated_rows[0, taken]
+ end
+ end
+
+ class Skip < Compound
+ def eval
+ unoperated_rows[skipped..-1]
+ end
+ end
+
+ class Group < Compound
+ def eval
+ raise NotImplementedError
+ end
+ end
+
+ class Alias < Compound
+ def eval
+ unoperated_rows
+ end
+ end
+
+ class Join < Relation
+ def eval
+ result = []
+ relation1.call.each do |row1|
+ relation2.call.each do |row2|
+ combined_row = row1.combine(row2, self)
+ if predicates.all? { |p| p.eval(combined_row) }
+ result << combined_row
+ end
+ end
+ end
+ result
+ end
+ end
+end