mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
removed more boiler-plate
This commit is contained in:
parent
9e5ee49ec5
commit
2d021c641a
9 changed files with 31 additions and 78 deletions
|
@ -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 = {})
|
||||
|
@ -29,26 +30,6 @@ module Arel
|
|||
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)
|
||||
klass.send :alias_method, :eql?, :==
|
||||
|
@ -85,6 +66,18 @@ module Arel
|
|||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1,6 +1,7 @@
|
|||
module Arel
|
||||
class Update < Compound
|
||||
attr_reader :assignments
|
||||
attributes :relation, :assignments
|
||||
deriving :==
|
||||
|
||||
def initialize(relation, assignments)
|
||||
@relation, @assignments = relation, assignments.bind(relation)
|
||||
|
@ -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
|
Loading…
Reference in a new issue