Skip to content

Commit

Permalink
Expand usages of #hash_on. The #hash definition it produces looks bro…
Browse files Browse the repository at this point in the history
…ken, but leaving it for now
  • Loading branch information
brynary committed May 18, 2009
1 parent 930c9f9 commit 65e419c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
10 changes: 0 additions & 10 deletions lib/arel/algebra/extensions/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ def ==(other)
}
class_eval methods[method_name], __FILE__, __LINE__
end

def hash_on(delegatee)
define_method :eql? do |other|
self == other
end

define_method :hash do
@hash ||= delegatee.hash
end
end

Class.send(:include, self)
end
Expand Down
9 changes: 8 additions & 1 deletion lib/arel/algebra/relations/operations/join.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ class Join < Relation
attributes :relation1, :relation2, :predicates
deriving :==
delegate :name, :to => :relation1
hash_on :relation1

def initialize(relation1, relation2 = Nil.instance, *predicates)
@relation1, @relation2, @predicates = relation1, relation2, predicates
end

def hash
@hash ||= :relation1.hash
end

def eql?(other)
self == other
end

def attributes
@attributes ||= (relation1.externalize.attributes +
relation2.externalize.attributes).collect { |a| a.bind(self) }
Expand Down
12 changes: 10 additions & 2 deletions lib/arel/algebra/relations/utilities/compound.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Arel
class Compound < Relation
attr_reader :relation
hash_on :relation
delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?,
:column_for, :engine,
:to => :relation
Expand All @@ -14,7 +13,16 @@ def #{operation_name}
OPERATION
end

private
def hash
@hash ||= :relation.hash
end

def eql?(other)
self == other
end

private

def arguments_from_block(relation, &block)
block_given?? [yield(relation)] : []
end
Expand Down
9 changes: 8 additions & 1 deletion lib/arel/engines/sql/relations/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Table < Relation

cattr_accessor :engine
attr_reader :name, :engine
hash_on :name

def initialize(name, engine = Table.engine)
@name, @engine = name.to_s, engine
Expand All @@ -16,6 +15,14 @@ def attributes
end
end

def eql?(other)
self == other
end

def hash
@hash ||= :name.hash
end

def format(attribute, value)
attribute.column.type_cast(value)
end
Expand Down

0 comments on commit 65e419c

Please sign in to comment.