diff --git a/lib/active_relation.rb b/lib/active_relation.rb index f04825ad4c..5b5c91706f 100644 --- a/lib/active_relation.rb +++ b/lib/active_relation.rb @@ -4,8 +4,8 @@ require 'rubygems' require 'activesupport' require 'activerecord' -require 'active_relation/sql' require 'active_relation/extensions' +require 'active_relation/sql' require 'active_relation/predicates' require 'active_relation/relations' require 'active_relation/engines' diff --git a/lib/active_relation/extensions.rb b/lib/active_relation/extensions.rb index 8a024947ed..7268a5549b 100644 --- a/lib/active_relation/extensions.rb +++ b/lib/active_relation/extensions.rb @@ -1,3 +1,4 @@ require 'active_relation/extensions/object' +require 'active_relation/extensions/class' require 'active_relation/extensions/array' require 'active_relation/extensions/hash' diff --git a/lib/active_relation/extensions/class.rb b/lib/active_relation/extensions/class.rb new file mode 100644 index 0000000000..0e5b728c26 --- /dev/null +++ b/lib/active_relation/extensions/class.rb @@ -0,0 +1,17 @@ +class Class + def abstract(*methods) + methods.each do |method| + define_method method do + raise NotImplementedError + end + end + end + + def hash_on(delegatee) + define_method :eql? do |other| + self == other + end + + delegate :hash, :to => delegatee + end +end \ No newline at end of file diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb index ab874150ed..90eb73f0b0 100644 --- a/lib/active_relation/extensions/object.rb +++ b/lib/active_relation/extensions/object.rb @@ -1,12 +1,4 @@ -class Object - def self.hash_on(delegatee) - def eql?(other) - self == other - end - - delegate :hash, :to => delegatee - end - +class Object def bind(relation) ActiveRelation::Value.new(self, relation) end diff --git a/lib/active_relation/sql.rb b/lib/active_relation/sql.rb index b38e6dc392..e5a4eed08b 100644 --- a/lib/active_relation/sql.rb +++ b/lib/active_relation/sql.rb @@ -8,6 +8,8 @@ module ActiveRelation attr_reader :engine include Quoting + abstract :attribute, :select, :value + def initialize(engine) @engine = engine end diff --git a/spec/active_relation/unit/relations/compound_spec.rb b/spec/active_relation/unit/relations/compound_spec.rb index d271529998..e8fcd12e2c 100644 --- a/spec/active_relation/unit/relations/compound_spec.rb +++ b/spec/active_relation/unit/relations/compound_spec.rb @@ -21,13 +21,5 @@ module ActiveRelation @compound_relation.attributes.should == @relation.attributes.collect { |a| a.bind(@compound_relation) } end end - - describe 'hashing' do - it 'implements hash equality' do - hash = {} - hash[@compound_relation] = 1 - hash[ConcreteCompound.new(@relation)].should == 1 - end - end end end \ No newline at end of file