diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:31:04 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:31:04 -0400 |
commit | 7032a50297fce4d7724d1735e81e5df5fd919e71 (patch) | |
tree | c52333abcc7a1454ea6ada7fe5e31e054f4e9540 /lib | |
parent | bdca9ed42ffea10aa6989ea3ecebedb424fa01ed (diff) | |
download | rails-7032a50297fce4d7724d1735e81e5df5fd919e71.tar.gz rails-7032a50297fce4d7724d1735e81e5df5fd919e71.tar.bz2 rails-7032a50297fce4d7724d1735e81e5df5fd919e71.zip |
reorganized file structures
Conflicts:
lib/arel.rb
lib/arel/arel.rb
lib/arel/engines/memory/predicates.rb
lib/arel/engines/memory/relations/array.rb
lib/arel/engines/sql/relations/table.rb
Diffstat (limited to 'lib')
55 files changed, 145 insertions, 69 deletions
diff --git a/lib/arel.rb b/lib/arel.rb index f22287fcc5..fcca60758e 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -5,10 +5,6 @@ require 'activesupport' require 'activerecord' require 'active_record/connection_adapters/abstract/quoting' -require 'arel/arel' -require 'arel/extensions' -require 'arel/predicates' -require 'arel/relations' +require 'arel/algebra' require 'arel/engines' require 'arel/session' -require 'arel/primitives' diff --git a/lib/arel/algebra.rb b/lib/arel/algebra.rb new file mode 100644 index 0000000000..f27882a343 --- /dev/null +++ b/lib/arel/algebra.rb @@ -0,0 +1,4 @@ +require 'arel/algebra/extensions' +require 'arel/algebra/predicates' +require 'arel/algebra/relations' +require 'arel/algebra/primitives'
\ No newline at end of file diff --git a/lib/arel/algebra/extensions.rb b/lib/arel/algebra/extensions.rb new file mode 100644 index 0000000000..5338fee989 --- /dev/null +++ b/lib/arel/algebra/extensions.rb @@ -0,0 +1,4 @@ +require 'arel/algebra/extensions/object' +require 'arel/algebra/extensions/class' +require 'arel/algebra/extensions/array' +require 'arel/algebra/extensions/hash' diff --git a/lib/arel/extensions/array.rb b/lib/arel/algebra/extensions/array.rb index 5b6d6d6abd..5b6d6d6abd 100644 --- a/lib/arel/extensions/array.rb +++ b/lib/arel/algebra/extensions/array.rb diff --git a/lib/arel/extensions/class.rb b/lib/arel/algebra/extensions/class.rb index f37898e7d7..f37898e7d7 100644 --- a/lib/arel/extensions/class.rb +++ b/lib/arel/algebra/extensions/class.rb diff --git a/lib/arel/extensions/hash.rb b/lib/arel/algebra/extensions/hash.rb index 7472b5aa73..7472b5aa73 100644 --- a/lib/arel/extensions/hash.rb +++ b/lib/arel/algebra/extensions/hash.rb diff --git a/lib/arel/extensions/object.rb b/lib/arel/algebra/extensions/object.rb index d626407dcb..d626407dcb 100644 --- a/lib/arel/extensions/object.rb +++ b/lib/arel/algebra/extensions/object.rb diff --git a/lib/arel/algebra/extensions/pathname.rb b/lib/arel/algebra/extensions/pathname.rb new file mode 100644 index 0000000000..2f7e2733e7 --- /dev/null +++ b/lib/arel/algebra/extensions/pathname.rb @@ -0,0 +1,5 @@ +class Pathname + def /(path) + (self + path).expand_path + end +end
\ No newline at end of file diff --git a/lib/arel/algebra/predicates.rb b/lib/arel/algebra/predicates.rb new file mode 100644 index 0000000000..f83101306e --- /dev/null +++ b/lib/arel/algebra/predicates.rb @@ -0,0 +1,45 @@ +module Arel + class Predicate + end + + class Binary < Predicate + attributes :operand1, :operand2 + deriving :initialize + + def ==(other) + self.class === other and + @operand1 == other.operand1 and + @operand2 == other.operand2 + end + + def bind(relation) + self.class.new(operand1.find_correlate_in(relation), operand2.find_correlate_in(relation)) + end + end + + class Equality < Binary + def ==(other) + Equality === other and + ((operand1 == other.operand1 and operand2 == other.operand2) or + (operand1 == other.operand2 and operand2 == other.operand1)) + end + end + + class GreaterThanOrEqualTo < Binary + end + + class GreaterThan < Binary + end + + class LessThanOrEqualTo < Binary + end + + class LessThan < Binary + end + + class Match < Binary + end + + class In < Binary + end +end
\ No newline at end of file diff --git a/lib/arel/algebra/primitives.rb b/lib/arel/algebra/primitives.rb new file mode 100644 index 0000000000..a4c3169e0b --- /dev/null +++ b/lib/arel/algebra/primitives.rb @@ -0,0 +1,4 @@ +require 'arel/algebra/primitives/attribute' +require 'arel/algebra/primitives/value' +require 'arel/algebra/primitives/expression' + diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/algebra/primitives/attribute.rb index 5e216770e4..5e216770e4 100644 --- a/lib/arel/primitives/attribute.rb +++ b/lib/arel/algebra/primitives/attribute.rb diff --git a/lib/arel/primitives/expression.rb b/lib/arel/algebra/primitives/expression.rb index b67a5e1f8e..b67a5e1f8e 100644 --- a/lib/arel/primitives/expression.rb +++ b/lib/arel/algebra/primitives/expression.rb diff --git a/lib/arel/primitives/value.rb b/lib/arel/algebra/primitives/value.rb index 91c4045507..91c4045507 100644 --- a/lib/arel/primitives/value.rb +++ b/lib/arel/algebra/primitives/value.rb diff --git a/lib/arel/algebra/relations.rb b/lib/arel/algebra/relations.rb new file mode 100644 index 0000000000..03f04d2459 --- /dev/null +++ b/lib/arel/algebra/relations.rb @@ -0,0 +1,15 @@ +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/writes/delete' +require 'arel/algebra/relations/writes/update' +require 'arel/algebra/relations/writes/insert' +require 'arel/algebra/relations/operations/alias' +require 'arel/algebra/relations/operations/group' +require 'arel/algebra/relations/operations/join' +require 'arel/algebra/relations/operations/order' +require 'arel/algebra/relations/operations/project' +require 'arel/algebra/relations/operations/where' +require 'arel/algebra/relations/operations/skip' +require 'arel/algebra/relations/operations/take'
\ No newline at end of file diff --git a/lib/arel/relations/operations/alias.rb b/lib/arel/algebra/relations/operations/alias.rb index 67837f6a75..67837f6a75 100644 --- a/lib/arel/relations/operations/alias.rb +++ b/lib/arel/algebra/relations/operations/alias.rb diff --git a/lib/arel/relations/operations/group.rb b/lib/arel/algebra/relations/operations/group.rb index 04fd9fea62..04fd9fea62 100644 --- a/lib/arel/relations/operations/group.rb +++ b/lib/arel/algebra/relations/operations/group.rb diff --git a/lib/arel/relations/operations/join.rb b/lib/arel/algebra/relations/operations/join.rb index 8e19254378..8e19254378 100644 --- a/lib/arel/relations/operations/join.rb +++ b/lib/arel/algebra/relations/operations/join.rb diff --git a/lib/arel/relations/operations/order.rb b/lib/arel/algebra/relations/operations/order.rb index 05af3fde4d..05af3fde4d 100644 --- a/lib/arel/relations/operations/order.rb +++ b/lib/arel/algebra/relations/operations/order.rb diff --git a/lib/arel/relations/operations/project.rb b/lib/arel/algebra/relations/operations/project.rb index 5507ea3163..5507ea3163 100644 --- a/lib/arel/relations/operations/project.rb +++ b/lib/arel/algebra/relations/operations/project.rb diff --git a/lib/arel/relations/operations/skip.rb b/lib/arel/algebra/relations/operations/skip.rb index 930e4c94ea..930e4c94ea 100644 --- a/lib/arel/relations/operations/skip.rb +++ b/lib/arel/algebra/relations/operations/skip.rb diff --git a/lib/arel/relations/operations/take.rb b/lib/arel/algebra/relations/operations/take.rb index 2fd3fdf635..2fd3fdf635 100644 --- a/lib/arel/relations/operations/take.rb +++ b/lib/arel/algebra/relations/operations/take.rb diff --git a/lib/arel/relations/operations/where.rb b/lib/arel/algebra/relations/operations/where.rb index 608aaeb4b7..608aaeb4b7 100644 --- a/lib/arel/relations/operations/where.rb +++ b/lib/arel/algebra/relations/operations/where.rb diff --git a/lib/arel/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 20badaf165..20badaf165 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb diff --git a/lib/arel/relations/utilities/compound.rb b/lib/arel/algebra/relations/utilities/compound.rb index b1e8054d4d..e33b8dbf14 100644 --- a/lib/arel/relations/utilities/compound.rb +++ b/lib/arel/algebra/relations/utilities/compound.rb @@ -3,7 +3,7 @@ module Arel attr_reader :relation hash_on :relation delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?, - :column_for, :engine, :table, :table_sql, + :column_for, :engine, :table, :table_sql, :array, :to => :relation [:attributes, :wheres, :groupings, :orders].each do |operation_name| diff --git a/lib/arel/relations/utilities/externalization.rb b/lib/arel/algebra/relations/utilities/externalization.rb index bd067f2304..bd067f2304 100644 --- a/lib/arel/relations/utilities/externalization.rb +++ b/lib/arel/algebra/relations/utilities/externalization.rb diff --git a/lib/arel/relations/utilities/nil.rb b/lib/arel/algebra/relations/utilities/nil.rb index 6a9d678c45..6a9d678c45 100644 --- a/lib/arel/relations/utilities/nil.rb +++ b/lib/arel/algebra/relations/utilities/nil.rb diff --git a/lib/arel/relations/writes/delete.rb b/lib/arel/algebra/relations/writes/delete.rb index a94067c7fa..a94067c7fa 100644 --- a/lib/arel/relations/writes/delete.rb +++ b/lib/arel/algebra/relations/writes/delete.rb diff --git a/lib/arel/relations/writes/insert.rb b/lib/arel/algebra/relations/writes/insert.rb index 6d85e9769a..6d85e9769a 100644 --- a/lib/arel/relations/writes/insert.rb +++ b/lib/arel/algebra/relations/writes/insert.rb diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/algebra/relations/writes/update.rb index e647218a80..e647218a80 100644 --- a/lib/arel/relations/writes/update.rb +++ b/lib/arel/algebra/relations/writes/update.rb diff --git a/lib/arel/arel.rb b/lib/arel/arel.rb deleted file mode 100644 index 7780d45e25..0000000000 --- a/lib/arel/arel.rb +++ /dev/null @@ -1,3 +0,0 @@ -def Arel(name, engine = (Arel::Table.engine || ActiveRecord::Base.connection)) - Arel::Table.new(name, engine) -end diff --git a/lib/arel/engines.rb b/lib/arel/engines.rb index 63a929528f..3f854edf90 100644 --- a/lib/arel/engines.rb +++ b/lib/arel/engines.rb @@ -1,2 +1,2 @@ -require 'arel/engines/sql/sql' -require 'arel/engines/array/array'
\ No newline at end of file +require 'arel/engines/sql' +require 'arel/engines/memory'
\ No newline at end of file diff --git a/lib/arel/engines/array/array.rb b/lib/arel/engines/array/array.rb deleted file mode 100644 index 3a3a47308a..0000000000 --- a/lib/arel/engines/array/array.rb +++ /dev/null @@ -1 +0,0 @@ -require 'arel/engines/array/relations/array'
\ No newline at end of file diff --git a/lib/arel/engines/memory.rb b/lib/arel/engines/memory.rb new file mode 100644 index 0000000000..df6f6f3d48 --- /dev/null +++ b/lib/arel/engines/memory.rb @@ -0,0 +1,4 @@ +require 'arel/engines/memory/relations' +require 'arel/engines/memory/primitives' +require 'arel/engines/memory/engine' +require 'arel/engines/memory/predicates'
\ No newline at end of file diff --git a/lib/arel/engines/memory/engine.rb b/lib/arel/engines/memory/engine.rb new file mode 100644 index 0000000000..67a084f2cd --- /dev/null +++ b/lib/arel/engines/memory/engine.rb @@ -0,0 +1,12 @@ +module Arel + module Memory + class Engine + module CRUD + def read(relation) + relation.eval + end + end + include CRUD + end + end +end
\ No newline at end of file diff --git a/lib/arel/predicates.rb b/lib/arel/engines/memory/predicates.rb index aa206d4e96..3522ea3ffa 100644 --- a/lib/arel/predicates.rb +++ b/lib/arel/engines/memory/predicates.rb @@ -10,17 +10,8 @@ module Arel end class Binary < Predicate - attributes :operand1, :operand2 - deriving :initialize - - def ==(other) - self.class === other and - @operand1 == other.operand1 and - @operand2 == other.operand2 - end - - def bind(relation) - self.class.new(operand1.find_correlate_in(relation), operand2.find_correlate_in(relation)) + def eval(row) + operand1.eval(row).send(operator, operand2.eval(row)) end end @@ -56,6 +47,7 @@ module Arel end class LessThan < Binary + def operator; :< end end class Match < Binary diff --git a/lib/arel/engines/memory/primitives.rb b/lib/arel/engines/memory/primitives.rb new file mode 100644 index 0000000000..4d5c76e956 --- /dev/null +++ b/lib/arel/engines/memory/primitives.rb @@ -0,0 +1,2 @@ +require 'arel/engines/memory/primitives/attribute' +require 'arel/engines/memory/primitives/value' diff --git a/lib/arel/engines/memory/primitives/attribute.rb b/lib/arel/engines/memory/primitives/attribute.rb new file mode 100644 index 0000000000..9864feadc2 --- /dev/null +++ b/lib/arel/engines/memory/primitives/attribute.rb @@ -0,0 +1,7 @@ +module Arel + class Attribute + def eval(row) + row[self] + end + end +end
\ No newline at end of file diff --git a/lib/arel/engines/memory/primitives/value.rb b/lib/arel/engines/memory/primitives/value.rb new file mode 100644 index 0000000000..b83cd02e57 --- /dev/null +++ b/lib/arel/engines/memory/primitives/value.rb @@ -0,0 +1,7 @@ +module Arel + class Value + def eval(row) + value + end + end +end
\ No newline at end of file diff --git a/lib/arel/engines/memory/relations.rb b/lib/arel/engines/memory/relations.rb new file mode 100644 index 0000000000..6361d7c9d7 --- /dev/null +++ b/lib/arel/engines/memory/relations.rb @@ -0,0 +1,2 @@ +require 'arel/engines/memory/relations/array' +require 'arel/engines/memory/relations/operations/where' diff --git a/lib/arel/engines/array/relations/array.rb b/lib/arel/engines/memory/relations/array.rb index dac65abbc2..c02c62891b 100644 --- a/lib/arel/engines/array/relations/array.rb +++ b/lib/arel/engines/memory/relations/array.rb @@ -1,9 +1,11 @@ module Arel class Array < Relation + attributes :array, :attribute_names + deriving :initialize include Recursion::BaseCase - - def initialize(array, attribute_names) - @array, @attribute_names = array, attribute_names + + def engine + @engine ||= Memory::Engine.new end def attributes @@ -12,7 +14,7 @@ module Arel end end - def call(connection = nil) + def eval @array.collect { |row| attributes.zip(row).to_hash } end end diff --git a/lib/arel/engines/memory/relations/operations/where.rb b/lib/arel/engines/memory/relations/operations/where.rb new file mode 100644 index 0000000000..eb11fb55fd --- /dev/null +++ b/lib/arel/engines/memory/relations/operations/where.rb @@ -0,0 +1,7 @@ +module Arel + class Where < Compound + def eval + relation.eval.select { |row| predicate.eval(row) } + end + end +end
\ No newline at end of file diff --git a/lib/arel/engines/sql/sql.rb b/lib/arel/engines/sql.rb index aed1fd861e..aed1fd861e 100644 --- a/lib/arel/engines/sql/sql.rb +++ b/lib/arel/engines/sql.rb diff --git a/lib/arel/engines/sql/primitives/attribute.rb b/lib/arel/engines/sql/primitives/attribute.rb index 48de690b6f..ad78a9ec5b 100644 --- a/lib/arel/engines/sql/primitives/attribute.rb +++ b/lib/arel/engines/sql/primitives/attribute.rb @@ -1,5 +1,3 @@ -require 'set' - module Arel class Attribute def column diff --git a/lib/arel/engines/sql/relations.rb b/lib/arel/engines/sql/relations.rb index 4de01b2691..39ef8852a1 100644 --- a/lib/arel/engines/sql/relations.rb +++ b/lib/arel/engines/sql/relations.rb @@ -1,5 +1,10 @@ -require 'arel/engines/sql/relations/utilities' +require 'arel/engines/sql/relations/utilities/recursion' +require 'arel/engines/sql/relations/utilities/externalization' +require 'arel/engines/sql/relations/utilities/nil' require 'arel/engines/sql/relations/relation' -require 'arel/engines/sql/relations/operations' -require 'arel/engines/sql/relations/writes' -require 'arel/engines/sql/relations/table'
\ No newline at end of file +require 'arel/engines/sql/relations/table' +require 'arel/engines/sql/relations/operations/join' +require 'arel/engines/sql/relations/operations/alias' +require 'arel/engines/sql/relations/writes/delete' +require 'arel/engines/sql/relations/writes/insert' +require 'arel/engines/sql/relations/writes/update'
\ No newline at end of file diff --git a/lib/arel/engines/sql/relations/operations.rb b/lib/arel/engines/sql/relations/operations.rb deleted file mode 100644 index ff33fc6bc3..0000000000 --- a/lib/arel/engines/sql/relations/operations.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'arel/engines/sql/relations/operations/alias' -require 'arel/engines/sql/relations/operations/join' diff --git a/lib/arel/engines/sql/relations/table.rb b/lib/arel/engines/sql/relations/table.rb index 0433abbbb2..2653744149 100644 --- a/lib/arel/engines/sql/relations/table.rb +++ b/lib/arel/engines/sql/relations/table.rb @@ -34,3 +34,8 @@ module Arel end end end + +def Table(name, engine = Arel::Table.engine) + Arel::Table.new(name, engine) +end + diff --git a/lib/arel/engines/sql/relations/utilities.rb b/lib/arel/engines/sql/relations/utilities.rb deleted file mode 100644 index a1451ed448..0000000000 --- a/lib/arel/engines/sql/relations/utilities.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'arel/engines/sql/relations/utilities/recursion' -require 'arel/engines/sql/relations/utilities/externalization' -require 'arel/engines/sql/relations/utilities/nil' diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb deleted file mode 100644 index dcadc326d9..0000000000 --- a/lib/arel/engines/sql/relations/writes.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'arel/engines/sql/relations/writes/delete' -require 'arel/engines/sql/relations/writes/insert' -require 'arel/engines/sql/relations/writes/update' diff --git a/lib/arel/extensions.rb b/lib/arel/extensions.rb deleted file mode 100644 index 299ba0631c..0000000000 --- a/lib/arel/extensions.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'arel/extensions/object' -require 'arel/extensions/class' -require 'arel/extensions/array' -require 'arel/extensions/hash' diff --git a/lib/arel/primitives.rb b/lib/arel/primitives.rb deleted file mode 100644 index d84713d3d5..0000000000 --- a/lib/arel/primitives.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'arel/primitives/attribute' -require 'arel/primitives/value' -require 'arel/primitives/expression' - diff --git a/lib/arel/relations.rb b/lib/arel/relations.rb deleted file mode 100644 index f97c35e56e..0000000000 --- a/lib/arel/relations.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'arel/relations/relation' -require 'arel/relations/utilities' -require 'arel/relations/writes' -require 'arel/relations/operations'
\ No newline at end of file diff --git a/lib/arel/relations/operations.rb b/lib/arel/relations/operations.rb deleted file mode 100644 index c598c7fcc9..0000000000 --- a/lib/arel/relations/operations.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'arel/relations/operations/alias' -require 'arel/relations/operations/group' -require 'arel/relations/operations/join' -require 'arel/relations/operations/order' -require 'arel/relations/operations/project' -require 'arel/relations/operations/where' -require 'arel/relations/operations/skip' -require 'arel/relations/operations/take'
\ No newline at end of file diff --git a/lib/arel/relations/utilities.rb b/lib/arel/relations/utilities.rb deleted file mode 100644 index fbd949ef0c..0000000000 --- a/lib/arel/relations/utilities.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'arel/relations/utilities/compound' -require 'arel/relations/utilities/nil' -require 'arel/relations/utilities/externalization' diff --git a/lib/arel/relations/writes.rb b/lib/arel/relations/writes.rb deleted file mode 100644 index 1495d9c857..0000000000 --- a/lib/arel/relations/writes.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'arel/relations/writes/delete' -require 'arel/relations/writes/update' -require 'arel/relations/writes/insert'
\ No newline at end of file diff --git a/lib/arel/session.rb b/lib/arel/session.rb index 9c2ddc535b..cf04e8a93a 100644 --- a/lib/arel/session.rb +++ b/lib/arel/session.rb @@ -1,5 +1,3 @@ -require 'singleton' - module Arel class Session class << self |