From a29ceffc9476c99ff02f0617d2e38627c526bac2 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Tue, 11 Mar 2008 22:42:47 -0700 Subject: implemented hashing macro; implemented custom matcher testing this macro --- lib/active_relation/.DS_Store | Bin 6148 -> 6148 bytes lib/active_relation/extensions/object.rb | 10 +++++++++- lib/active_relation/primitives/attribute.rb | 5 +---- lib/active_relation/relations/relation.rb | 4 ---- lib/active_relation/relations/table.rb | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/active_relation/.DS_Store b/lib/active_relation/.DS_Store index 2a449ff62e..9918127870 100644 Binary files a/lib/active_relation/.DS_Store and b/lib/active_relation/.DS_Store differ diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb index d13cf9aabb..c1269ee37b 100644 --- a/lib/active_relation/extensions/object.rb +++ b/lib/active_relation/extensions/object.rb @@ -1,4 +1,12 @@ -class Object +class Object + def self.hash_on(delegatee) + def eql?(other) + self == other + end + + delegate :hash, :to => delegatee + end + def bind(relation) ActiveRelation::Scalar.new(self, relation) end diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb index baaae1973c..20677f824b 100644 --- a/lib/active_relation/primitives/attribute.rb +++ b/lib/active_relation/primitives/attribute.rb @@ -48,10 +48,7 @@ module ActiveRelation module Congruence def self.included(klass) - klass.class_eval do - alias_method :eql?, :== - delegate :hash, :to => :name - end + klass.hash_on :name end def history diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index 1c97cc7035..f9823bf92d 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -102,10 +102,6 @@ module ActiveRelation false end - def eql?(other) - self == other - end - def to_sql(strategy = Sql::Relation.new(engine)) strategy.select [ "SELECT #{attributes.collect{ |a| a.to_sql(Sql::Projection.new(engine)) }.join(', ')}", diff --git a/lib/active_relation/relations/table.rb b/lib/active_relation/relations/table.rb index 84eb1213ee..4682298608 100644 --- a/lib/active_relation/relations/table.rb +++ b/lib/active_relation/relations/table.rb @@ -3,7 +3,7 @@ module ActiveRelation cattr_accessor :engine attr_reader :name, :engine - delegate :hash, :to => :name + hash_on :name def initialize(name, engine = Table.engine) @name, @engine = name.to_s, engine -- cgit v1.2.3