diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 14:13:00 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 14:13:00 -0700 |
commit | 29fea82cc67259974a78a5ca8872bd515c9042ae (patch) | |
tree | 20725d098a3c8e3a1aba5a47e472daa0d410dfe8 /lib | |
parent | 7e4e37eae9ce82d42a10de2917bc97529fa4a4b3 (diff) | |
download | rails-29fea82cc67259974a78a5ca8872bd515c9042ae.tar.gz rails-29fea82cc67259974a78a5ca8872bd515c9042ae.tar.bz2 rails-29fea82cc67259974a78a5ca8872bd515c9042ae.zip |
more class organizing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/algebra/relations/operations/join.rb | 6 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/order.rb | 7 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/project.rb | 4 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/skip.rb | 4 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/take.rb | 4 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/where.rb | 4 | ||||
-rw-r--r-- | lib/arel/algebra/relations/relation.rb | 4 | ||||
-rw-r--r-- | lib/arel/engines/memory/relations/operations.rb | 33 |
8 files changed, 27 insertions, 39 deletions
diff --git a/lib/arel/algebra/relations/operations/join.rb b/lib/arel/algebra/relations/operations/join.rb index dd67e8a9bf..9eee84113a 100644 --- a/lib/arel/algebra/relations/operations/join.rb +++ b/lib/arel/algebra/relations/operations/join.rb @@ -70,10 +70,4 @@ module Arel relation1.engine end end - - module Relation - def join? - false - end - end end diff --git a/lib/arel/algebra/relations/operations/order.rb b/lib/arel/algebra/relations/operations/order.rb index 582abf642c..94bd7bcd59 100644 --- a/lib/arel/algebra/relations/operations/order.rb +++ b/lib/arel/algebra/relations/operations/order.rb @@ -31,5 +31,12 @@ module Arel engine end end + + def eval + unoperated_rows.sort do |row1, row2| + ordering = orders.detect { |o| o.eval(row1, row2) != 0 } || orders.last + ordering.eval(row1, row2) + end + end end end diff --git a/lib/arel/algebra/relations/operations/project.rb b/lib/arel/algebra/relations/operations/project.rb index 2cdae288e3..daca742039 100644 --- a/lib/arel/algebra/relations/operations/project.rb +++ b/lib/arel/algebra/relations/operations/project.rb @@ -22,5 +22,9 @@ module Arel relation == other.relation && projections == other.projections end + + def eval + unoperated_rows.collect { |r| r.slice(*projections) } + end end end diff --git a/lib/arel/algebra/relations/operations/skip.rb b/lib/arel/algebra/relations/operations/skip.rb index f6a58d15bd..5a87fbb7b5 100644 --- a/lib/arel/algebra/relations/operations/skip.rb +++ b/lib/arel/algebra/relations/operations/skip.rb @@ -24,5 +24,9 @@ module Arel engine end end + + def eval + unoperated_rows[skipped..-1] + end end end diff --git a/lib/arel/algebra/relations/operations/take.rb b/lib/arel/algebra/relations/operations/take.rb index 964aacacca..7098d578d5 100644 --- a/lib/arel/algebra/relations/operations/take.rb +++ b/lib/arel/algebra/relations/operations/take.rb @@ -28,5 +28,9 @@ module Arel def externalizable? true end + + def eval + unoperated_rows[0, taken] + end end end diff --git a/lib/arel/algebra/relations/operations/where.rb b/lib/arel/algebra/relations/operations/where.rb index e8db2ec8b0..b447b18809 100644 --- a/lib/arel/algebra/relations/operations/where.rb +++ b/lib/arel/algebra/relations/operations/where.rb @@ -30,5 +30,9 @@ module Arel engine end end + + def eval + unoperated_rows.select { |row| predicates.all? { |p| p.eval(row) } } + end end end diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 3ed3a43503..17a2cf3190 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -6,6 +6,10 @@ module Arel Session.instance end + def join? + false + end + def call engine.read(self) end diff --git a/lib/arel/engines/memory/relations/operations.rb b/lib/arel/engines/memory/relations/operations.rb index d026db460d..f233c48db0 100644 --- a/lib/arel/engines/memory/relations/operations.rb +++ b/lib/arel/engines/memory/relations/operations.rb @@ -1,37 +1,4 @@ module Arel - class Where < Compound - def eval - unoperated_rows.select { |row| predicates.all? { |p| p.eval(row) } } - end - end - - class Order < Compound - def eval - unoperated_rows.sort do |row1, row2| - ordering = orders.detect { |o| o.eval(row1, row2) != 0 } || orders.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 From < Compound def eval unoperated_rows[sources..-1] |