aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-17 14:38:09 -0400
committerBryan Helmkamp <bryan@brynary.com>2009-05-17 14:38:09 -0400
commitb0a45d52fdb7d8ce564f4dc2013bc790f98f1da3 (patch)
treee9553add3be978b3392735a40b869bfdbc53ea7a /lib
parent7032a50297fce4d7724d1735e81e5df5fd919e71 (diff)
downloadrails-b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3.tar.gz
rails-b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3.tar.bz2
rails-b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3.zip
consolidated files
Conflicts: lib/arel/algebra/predicates.rb lib/arel/algebra/relations/writes/delete.rb lib/arel/algebra/relations/writes/insert.rb lib/arel/algebra/relations/writes/update.rb lib/arel/engines/memory/predicates.rb lib/arel/engines/memory/relations.rb lib/arel/engines/sql/primitives/attribute.rb lib/arel/engines/sql/relations/writes/insert.rb lib/arel/engines/sql/relations/writes/update.rb
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/algebra/predicates.rb30
-rw-r--r--lib/arel/algebra/relations.rb4
-rw-r--r--lib/arel/algebra/relations/writes.rb36
-rw-r--r--lib/arel/algebra/relations/writes/delete.rb10
-rw-r--r--lib/arel/algebra/relations/writes/insert.rb14
-rw-r--r--lib/arel/algebra/relations/writes/update.rb14
-rw-r--r--lib/arel/engines/memory/predicates.rb14
-rw-r--r--lib/arel/engines/memory/primitives.rb15
-rw-r--r--lib/arel/engines/memory/primitives/attribute.rb7
-rw-r--r--lib/arel/engines/memory/primitives/value.rb7
-rw-r--r--lib/arel/engines/memory/relations.rb3
-rw-r--r--lib/arel/engines/memory/relations/operations.rb (renamed from lib/arel/engines/memory/relations/operations/where.rb)0
-rw-r--r--lib/arel/engines/sql/primitives.rb34
-rw-r--r--lib/arel/engines/sql/primitives/attribute.rb15
-rw-r--r--lib/arel/engines/sql/primitives/expression.rb7
-rw-r--r--lib/arel/engines/sql/primitives/value.rb11
-rw-r--r--lib/arel/engines/sql/relations.rb4
-rw-r--r--lib/arel/engines/sql/relations/writes.rb36
-rw-r--r--lib/arel/engines/sql/relations/writes/delete.rb12
-rw-r--r--lib/arel/engines/sql/relations/writes/insert.rb12
-rw-r--r--lib/arel/engines/sql/relations/writes/update.rb14
21 files changed, 133 insertions, 166 deletions
diff --git a/lib/arel/algebra/predicates.rb b/lib/arel/algebra/predicates.rb
index f83101306e..7f093ded6d 100644
--- a/lib/arel/algebra/predicates.rb
+++ b/lib/arel/algebra/predicates.rb
@@ -1,5 +1,12 @@
module Arel
class Predicate
+ def or(other_predicate)
+ Or.new(self, other_predicate)
+ end
+
+ def and(other_predicate)
+ And.new(self, other_predicate)
+ end
end
class Binary < Predicate
@@ -25,21 +32,10 @@ module Arel
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
+ 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/relations.rb b/lib/arel/algebra/relations.rb
index 03f04d2459..b75a31e5e3 100644
--- a/lib/arel/algebra/relations.rb
+++ b/lib/arel/algebra/relations.rb
@@ -2,9 +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/writes/delete'
-require 'arel/algebra/relations/writes/update'
-require 'arel/algebra/relations/writes/insert'
+require 'arel/algebra/relations/writes'
require 'arel/algebra/relations/operations/alias'
require 'arel/algebra/relations/operations/group'
require 'arel/algebra/relations/operations/join'
diff --git a/lib/arel/algebra/relations/writes.rb b/lib/arel/algebra/relations/writes.rb
new file mode 100644
index 0000000000..352f7bc7e5
--- /dev/null
+++ b/lib/arel/algebra/relations/writes.rb
@@ -0,0 +1,36 @@
+module Arel
+ class Deletion < Compound
+ attributes :relation
+ deriving :initialize, :==
+
+ def call
+ engine.delete(self)
+ end
+ end
+
+ class Insert < Compound
+ attributes :relation, :record
+ deriving :==
+
+ def initialize(relation, record)
+ @relation, @record = relation, record.bind(relation)
+ end
+
+ def call
+ engine.create(self)
+ end
+ end
+
+ class Update < Compound
+ attributes :relation, :assignments
+ deriving :==
+
+ def initialize(relation, assignments)
+ @relation, @assignments = relation, assignments.bind(relation)
+ end
+
+ def call
+ engine.update(self)
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/arel/algebra/relations/writes/delete.rb b/lib/arel/algebra/relations/writes/delete.rb
deleted file mode 100644
index a94067c7fa..0000000000
--- a/lib/arel/algebra/relations/writes/delete.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-module Arel
- class Deletion < Compound
- attributes :relation
- deriving :initialize, :==
-
- def call
- engine.delete(self)
- end
- end
-end
diff --git a/lib/arel/algebra/relations/writes/insert.rb b/lib/arel/algebra/relations/writes/insert.rb
deleted file mode 100644
index 6d85e9769a..0000000000
--- a/lib/arel/algebra/relations/writes/insert.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module Arel
- class Insert < Compound
- attributes :relation, :record
- deriving :==
-
- def initialize(relation, record)
- @relation, @record = relation, record.bind(relation)
- end
-
- def call
- engine.create(self)
- end
- end
-end
diff --git a/lib/arel/algebra/relations/writes/update.rb b/lib/arel/algebra/relations/writes/update.rb
deleted file mode 100644
index e647218a80..0000000000
--- a/lib/arel/algebra/relations/writes/update.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module Arel
- class Update < Compound
- attributes :relation, :assignments
- deriving :==
-
- def initialize(relation, assignments)
- @relation, @assignments = relation, assignments
- end
-
- def call
- engine.update(self)
- end
- end
-end
diff --git a/lib/arel/engines/memory/predicates.rb b/lib/arel/engines/memory/predicates.rb
index 3522ea3ffa..bbf39ba794 100644
--- a/lib/arel/engines/memory/predicates.rb
+++ b/lib/arel/engines/memory/predicates.rb
@@ -1,13 +1,4 @@
module Arel
- class Predicate
- def or(other_predicate)
- Or.new(self, other_predicate)
- end
-
- def and(other_predicate)
- And.new(self, other_predicate)
- end
- end
class Binary < Predicate
def eval(row)
@@ -30,11 +21,6 @@ module Arel
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
diff --git a/lib/arel/engines/memory/primitives.rb b/lib/arel/engines/memory/primitives.rb
index 4d5c76e956..77d4c1a52c 100644
--- a/lib/arel/engines/memory/primitives.rb
+++ b/lib/arel/engines/memory/primitives.rb
@@ -1,2 +1,13 @@
-require 'arel/engines/memory/primitives/attribute'
-require 'arel/engines/memory/primitives/value'
+module Arel
+ class Attribute
+ def eval(row)
+ row[self]
+ end
+ end
+
+ class Value
+ def eval(row)
+ value
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/arel/engines/memory/primitives/attribute.rb b/lib/arel/engines/memory/primitives/attribute.rb
deleted file mode 100644
index 9864feadc2..0000000000
--- a/lib/arel/engines/memory/primitives/attribute.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-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
deleted file mode 100644
index b83cd02e57..0000000000
--- a/lib/arel/engines/memory/primitives/value.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-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
index 6361d7c9d7..9f8264c439 100644
--- a/lib/arel/engines/memory/relations.rb
+++ b/lib/arel/engines/memory/relations.rb
@@ -1,2 +1,3 @@
require 'arel/engines/memory/relations/array'
-require 'arel/engines/memory/relations/operations/where'
+require 'arel/engines/memory/relations/operations'
+
diff --git a/lib/arel/engines/memory/relations/operations/where.rb b/lib/arel/engines/memory/relations/operations.rb
index eb11fb55fd..eb11fb55fd 100644
--- a/lib/arel/engines/memory/relations/operations/where.rb
+++ b/lib/arel/engines/memory/relations/operations.rb
diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb
index 405b1ca803..5544d63710 100644
--- a/lib/arel/engines/sql/primitives.rb
+++ b/lib/arel/engines/sql/primitives.rb
@@ -1,3 +1,31 @@
-require 'arel/engines/sql/primitives/attribute'
-require 'arel/engines/sql/primitives/value'
-require 'arel/engines/sql/primitives/expression' \ No newline at end of file
+module Arel
+ class Attribute
+ def column
+ original_relation.column_for(self)
+ end
+
+ def format(object)
+ object.to_sql(Sql::Attribute.new(self))
+ end
+
+ def to_sql(formatter = Sql::WhereCondition.new(relation))
+ formatter.attribute self
+ end
+ end
+
+ class Expression < Attribute
+ def to_sql(formatter = Sql::SelectClause.new(relation))
+ formatter.expression self
+ end
+ end
+
+ class Value
+ def to_sql(formatter = Sql::WhereCondition.new(relation))
+ formatter.value value
+ end
+
+ def format(object)
+ object.to_sql(Sql::Value.new(relation))
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/arel/engines/sql/primitives/attribute.rb b/lib/arel/engines/sql/primitives/attribute.rb
deleted file mode 100644
index ad78a9ec5b..0000000000
--- a/lib/arel/engines/sql/primitives/attribute.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module Arel
- class Attribute
- def column
- original_relation.column_for(self)
- end
-
- def format(object)
- object.to_sql(Sql::Attribute.new(self))
- end
-
- def to_sql(formatter = Sql::WhereCondition.new(relation))
- formatter.attribute self
- end
- end
-end \ No newline at end of file
diff --git a/lib/arel/engines/sql/primitives/expression.rb b/lib/arel/engines/sql/primitives/expression.rb
deleted file mode 100644
index 24f6879848..0000000000
--- a/lib/arel/engines/sql/primitives/expression.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Arel
- class Expression < Attribute
- def to_sql(formatter = Sql::SelectClause.new(relation))
- formatter.expression self
- end
- end
-end \ No newline at end of file
diff --git a/lib/arel/engines/sql/primitives/value.rb b/lib/arel/engines/sql/primitives/value.rb
deleted file mode 100644
index a44acc26e0..0000000000
--- a/lib/arel/engines/sql/primitives/value.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Arel
- class Value
- def to_sql(formatter = Sql::WhereCondition.new(relation))
- formatter.value value
- end
-
- def format(object)
- object.to_sql(Sql::Value.new(relation))
- end
- end
-end \ No newline at end of file
diff --git a/lib/arel/engines/sql/relations.rb b/lib/arel/engines/sql/relations.rb
index 39ef8852a1..d6e4d295ba 100644
--- a/lib/arel/engines/sql/relations.rb
+++ b/lib/arel/engines/sql/relations.rb
@@ -5,6 +5,4 @@ require 'arel/engines/sql/relations/relation'
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
+require 'arel/engines/sql/relations/writes' \ No newline at end of file
diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb
new file mode 100644
index 0000000000..edfd9f7233
--- /dev/null
+++ b/lib/arel/engines/sql/relations/writes.rb
@@ -0,0 +1,36 @@
+module Arel
+ class Deletion < Compound
+ def to_sql(formatter = nil)
+ [
+ "DELETE",
+ "FROM #{table_sql}",
+ ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
+ ("LIMIT #{taken}" unless taken.blank? ),
+ ].compact.join("\n")
+ end
+ end
+
+ class Insert < Compound
+ def to_sql(formatter = nil)
+ [
+ "INSERT",
+ "INTO #{table_sql}",
+ "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})",
+ "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})"
+ ].join("\n")
+ end
+ end
+
+ class Update < Compound
+ def to_sql(formatter = nil)
+ [
+ "UPDATE #{table_sql} SET",
+ assignments.collect do |attribute, value|
+ "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}"
+ end.join(",\n"),
+ ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
+ ("LIMIT #{taken}" unless taken.blank? )
+ ].join("\n")
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/arel/engines/sql/relations/writes/delete.rb b/lib/arel/engines/sql/relations/writes/delete.rb
deleted file mode 100644
index b22ee51e24..0000000000
--- a/lib/arel/engines/sql/relations/writes/delete.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-module Arel
- class Deletion < Compound
- def to_sql(formatter = nil)
- [
- "DELETE",
- "FROM #{table_sql}",
- ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
- ("LIMIT #{taken}" unless taken.blank? ),
- ].compact.join("\n")
- end
- end
-end \ No newline at end of file
diff --git a/lib/arel/engines/sql/relations/writes/insert.rb b/lib/arel/engines/sql/relations/writes/insert.rb
deleted file mode 100644
index aac9c87a5b..0000000000
--- a/lib/arel/engines/sql/relations/writes/insert.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-module Arel
- class Insert < Compound
- def to_sql(formatter = nil)
- [
- "INSERT",
- "INTO #{table_sql}",
- "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})",
- "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})"
- ].join("\n")
- end
- end
-end \ No newline at end of file
diff --git a/lib/arel/engines/sql/relations/writes/update.rb b/lib/arel/engines/sql/relations/writes/update.rb
deleted file mode 100644
index 3e35a0d5cc..0000000000
--- a/lib/arel/engines/sql/relations/writes/update.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module Arel
- class Update < Compound
- def to_sql(formatter = nil)
- [
- "UPDATE #{table_sql} SET",
- assignments.collect do |attribute, value|
- "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}"
- end.join(",\n"),
- ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
- ("LIMIT #{taken}" unless taken.blank? )
- ].join("\n")
- end
- end
-end \ No newline at end of file