aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-19 19:38:36 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-19 19:38:36 -0700
commit2d021c641ab8c9215df863531cfb0d8ff8b9554a (patch)
treeda95d1423997ade3b000b0c210c44c2936c87f57 /lib
parent9e5ee49ec55b9cb1c2b4444dee58f3dfaefc7c7e (diff)
downloadrails-2d021c641ab8c9215df863531cfb0d8ff8b9554a.tar.gz
rails-2d021c641ab8c9215df863531cfb0d8ff8b9554a.tar.bz2
rails-2d021c641ab8c9215df863531cfb0d8ff8b9554a.zip
removed more boiler-plate
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/primitives/attribute.rb37
-rw-r--r--lib/arel/primitives/expression.rb11
-rw-r--r--lib/arel/primitives/value.rb12
-rw-r--r--lib/arel/relations/operations/join.rb2
-rw-r--r--lib/arel/relations/utilities/aggregation.rb11
-rw-r--r--lib/arel/relations/utilities/nil.rb6
-rw-r--r--lib/arel/relations/writes/delete.rb10
-rw-r--r--lib/arel/relations/writes/insert.rb9
-rw-r--r--lib/arel/relations/writes/update.rb11
9 files changed, 31 insertions, 78 deletions
diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb
index ca1d31ffcf..dffe24d121 100644
--- a/lib/arel/primitives/attribute.rb
+++ b/lib/arel/primitives/attribute.rb
@@ -2,7 +2,8 @@ require 'set'
module Arel
class Attribute
- attr_reader :relation, :name, :alias, :ancestor
+ attributes :relation, :name, :alias, :ancestor
+ deriving :==
delegate :engine, :christener, :to => :relation
def initialize(relation, name, options = {})
@@ -28,26 +29,6 @@ module Arel
def to_sql(formatter = Sql::WhereCondition.new(relation))
formatter.attribute self
end
-
- def ==(other)
- Attribute === other and
- name == other.name and
- @alias == other.alias and
- ancestor == other.ancestor and
- relation == other.relation
- end
-
- def original_relation
- @original_relation ||= original_attribute.relation
- end
-
- def original_attribute
- @original_attribute ||= history.detect { |a| !a.join? }
- end
-
- def find_correlate_in(relation)
- relation[self]
- end
module Transformations
def self.included(klass)
@@ -80,11 +61,23 @@ module Arel
def join?
relation.join?
end
-
+
def root
history.last
end
+ def original_relation
+ @original_relation ||= original_attribute.relation
+ end
+
+ def original_attribute
+ @original_attribute ||= history.detect { |a| !a.join? }
+ end
+
+ def find_correlate_in(relation)
+ relation[self]
+ end
+
def descends_from?(other)
history.include?(other)
end
diff --git a/lib/arel/primitives/expression.rb b/lib/arel/primitives/expression.rb
index 9afafcce2f..26186ccad8 100644
--- a/lib/arel/primitives/expression.rb
+++ b/lib/arel/primitives/expression.rb
@@ -1,6 +1,7 @@
module Arel
class Expression < Attribute
- attr_reader :attribute, :function_sql
+ attributes :attribute, :function_sql, :alias, :ancestor
+ deriving :==
delegate :relation, :to => :attribute
alias_method :name, :alias
@@ -16,14 +17,6 @@ module Arel
true
end
- def ==(other)
- Expression === other and
- attribute == other.attribute and
- function_sql == other.function_sql and
- ancestor == other.ancestor and
- @alias == other.alias
- end
-
module Transformations
def as(aliaz)
Expression.new(attribute, function_sql, aliaz, self)
diff --git a/lib/arel/primitives/value.rb b/lib/arel/primitives/value.rb
index 4509f13d17..809af7c206 100644
--- a/lib/arel/primitives/value.rb
+++ b/lib/arel/primitives/value.rb
@@ -1,12 +1,9 @@
module Arel
class Value
- attr_reader :value, :relation
-
+ attributes :value, :relation
+ deriving :initialize, :==
delegate :inclusion_predicate_sql, :equality_predicate_sql, :to => :value
- def initialize(value, relation)
- @value, @relation = value, relation
- end
def to_sql(formatter = Sql::WhereCondition.new(relation))
formatter.value value
@@ -16,11 +13,6 @@ module Arel
object.to_sql(Sql::Value.new(relation))
end
- def ==(other)
- Value === other and
- value == other.value
- end
-
def bind(relation)
Value.new(value, relation)
end
diff --git a/lib/arel/relations/operations/join.rb b/lib/arel/relations/operations/join.rb
index 01fa6da255..243a0289c7 100644
--- a/lib/arel/relations/operations/join.rb
+++ b/lib/arel/relations/operations/join.rb
@@ -5,7 +5,7 @@ module Arel
delegate :engine, :name, :to => :relation1
hash_on :relation1
- def initialize(join_sql, relation1, relation2 = Nil.new, *predicates)
+ def initialize(join_sql, relation1, relation2 = Nil.instance, *predicates)
@join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates
end
diff --git a/lib/arel/relations/utilities/aggregation.rb b/lib/arel/relations/utilities/aggregation.rb
index 66150bff0a..9f5ead8f86 100644
--- a/lib/arel/relations/utilities/aggregation.rb
+++ b/lib/arel/relations/utilities/aggregation.rb
@@ -1,11 +1,9 @@
module Arel
class Aggregation < Compound
+ attributes :relation
+ deriving :initialize, :==
include Recursion::BaseCase
- def initialize(relation)
- @relation = relation
- end
-
def wheres
[]
end
@@ -21,11 +19,6 @@ module Arel
def name
relation.name + '_aggregation'
end
-
- def ==(other)
- Aggregation === other and
- self.relation == other.relation
- end
end
class Relation
diff --git a/lib/arel/relations/utilities/nil.rb b/lib/arel/relations/utilities/nil.rb
index 2dcfb47233..2b8dc570f8 100644
--- a/lib/arel/relations/utilities/nil.rb
+++ b/lib/arel/relations/utilities/nil.rb
@@ -1,10 +1,8 @@
module Arel
class Nil < Relation
+ include Singleton
+
def table_sql(formatter = nil); '' end
def name; '' end
-
- def ==(other)
- Nil === other
- end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/writes/delete.rb b/lib/arel/relations/writes/delete.rb
index 2eaad6d1da..e72679c4d6 100644
--- a/lib/arel/relations/writes/delete.rb
+++ b/lib/arel/relations/writes/delete.rb
@@ -1,8 +1,7 @@
module Arel
class Deletion < Compound
- def initialize(relation)
- @relation = relation
- end
+ attributes :relation
+ deriving :initialize, :==
def to_sql(formatter = nil)
[
@@ -16,10 +15,5 @@ module Arel
def call(connection = engine.connection)
connection.delete(to_sql)
end
-
- def ==(other)
- Deletion === other and
- relation == other.relation
- end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/writes/insert.rb b/lib/arel/relations/writes/insert.rb
index a1c4c93de5..0545d7faa3 100644
--- a/lib/arel/relations/writes/insert.rb
+++ b/lib/arel/relations/writes/insert.rb
@@ -1,6 +1,7 @@
module Arel
class Insert < Compound
- attr_reader :record
+ attributes :relation, :record
+ deriving :==
def initialize(relation, record)
@relation, @record = relation, record.bind(relation)
@@ -18,11 +19,5 @@ module Arel
def call(connection = engine.connection)
connection.insert(to_sql)
end
-
- def ==(other)
- Insert === other and
- relation == other.relation and
- record == other.record
- end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb
index 760f4e931f..18b7ad9de1 100644
--- a/lib/arel/relations/writes/update.rb
+++ b/lib/arel/relations/writes/update.rb
@@ -1,7 +1,8 @@
module Arel
class Update < Compound
- attr_reader :assignments
-
+ attributes :relation, :assignments
+ deriving :==
+
def initialize(relation, assignments)
@relation, @assignments = relation, assignments.bind(relation)
end
@@ -20,11 +21,5 @@ module Arel
def call(connection = engine.connection)
connection.update(to_sql)
end
-
- def ==(other)
- Update === other and
- relation == other.relation and
- assignments == other.assignments
- end
end
end \ No newline at end of file