aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-12 18:08:25 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-12 18:08:25 -0800
commitc1e223f8a9e7394ede2fcd5621f7d43721023a20 (patch)
tree57f82f89cb0ebcedd81e73964a2f39a5e08818af
parentcebfc0c1d830799c8b26834760fe40b44efb2d08 (diff)
downloadrails-c1e223f8a9e7394ede2fcd5621f7d43721023a20.tar.gz
rails-c1e223f8a9e7394ede2fcd5621f7d43721023a20.tar.bz2
rails-c1e223f8a9e7394ede2fcd5621f7d43721023a20.zip
removed operator overloading of the predications (==, etc.)
-rw-r--r--lib/active_relation/predicates.rb6
-rw-r--r--lib/active_relation/relations/attribute.rb14
-rw-r--r--lib/active_relation/relations/order.rb2
-rw-r--r--lib/active_relation/relations/projection.rb2
-rw-r--r--lib/active_relation/relations/rename.rb6
-rw-r--r--spec/active_relation/integration/scratch_spec.rb8
-rw-r--r--spec/active_relation/relations/attribute_spec.rb32
7 files changed, 35 insertions, 35 deletions
diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb
index 5ac879899b..6616cfd414 100644
--- a/lib/active_relation/predicates.rb
+++ b/lib/active_relation/predicates.rb
@@ -14,7 +14,7 @@ module ActiveRelation
end
def ==(other)
- super and @attribute1.eql?(other.attribute1) and @attribute2.eql?(other.attribute2)
+ super and @attribute1 == other.attribute1 and @attribute2 == other.attribute2
end
def qualify
@@ -29,8 +29,8 @@ module ActiveRelation
class Equality < Binary
def ==(other)
self.class == other.class and
- ((attribute1.eql?(other.attribute1) and attribute2.eql?(other.attribute2)) or
- (attribute1.eql?(other.attribute2) and attribute2.eql?(other.attribute1)))
+ ((attribute1 == other.attribute1 and attribute2 == other.attribute2) or
+ (attribute1 == other.attribute2 and attribute2 == other.attribute1))
end
protected
diff --git a/lib/active_relation/relations/attribute.rb b/lib/active_relation/relations/attribute.rb
index b7233a4b17..2fe702cb14 100644
--- a/lib/active_relation/relations/attribute.rb
+++ b/lib/active_relation/relations/attribute.rb
@@ -21,32 +21,32 @@ module ActiveRelation
self.alias(qualified_name)
end
- def eql?(other)
+ def ==(other)
relation == other.relation and name == other.name and @alias == other.alias
end
module Predications
- def ==(other)
+ def equals(other)
Predicates::Equality.new(self, other)
end
- def <(other)
+ def less_than(other)
Predicates::LessThan.new(self, other)
end
- def <=(other)
+ def less_than_or_equal_to(other)
Predicates::LessThanOrEqualTo.new(self, other)
end
- def >(other)
+ def greater_than(other)
Predicates::GreaterThan.new(self, other)
end
- def >=(other)
+ def greater_than_or_equal_to(other)
Predicates::GreaterThanOrEqualTo.new(self, other)
end
- def =~(regexp)
+ def matches(regexp)
Predicates::Match.new(self, regexp)
end
end
diff --git a/lib/active_relation/relations/order.rb b/lib/active_relation/relations/order.rb
index 99ff939528..c8034d2f17 100644
--- a/lib/active_relation/relations/order.rb
+++ b/lib/active_relation/relations/order.rb
@@ -8,7 +8,7 @@ module ActiveRelation
end
def ==(other)
- relation == other.relation and orders.eql?(other.orders)
+ relation == other.relation and orders == other.orders
end
def qualify
diff --git a/lib/active_relation/relations/projection.rb b/lib/active_relation/relations/projection.rb
index b30c76898d..df25d16234 100644
--- a/lib/active_relation/relations/projection.rb
+++ b/lib/active_relation/relations/projection.rb
@@ -8,7 +8,7 @@ module ActiveRelation
end
def ==(other)
- relation == other.relation and attributes.eql?(other.attributes)
+ relation == other.relation and attributes == other.attributes
end
def qualify
diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb
index 7a1693df57..8f28c94d52 100644
--- a/lib/active_relation/relations/rename.rb
+++ b/lib/active_relation/relations/rename.rb
@@ -9,7 +9,7 @@ module ActiveRelation
end
def ==(other)
- relation == other.relation and schmattribute.eql?(other.schmattribute) and self.alias == other.alias
+ relation == other.relation and schmattribute == other.schmattribute and self.alias == other.alias
end
def attributes
@@ -24,14 +24,14 @@ module ActiveRelation
def attribute(name)
case
when name == self.alias then schmattribute.alias(self.alias)
- when relation[name].eql?(schmattribute) then nil
+ when relation[name] == schmattribute then nil
else relation[name]
end
end
private
def substitute(a)
- a.eql?(schmattribute) ? a.alias(self.alias) : a
+ a == schmattribute ? a.alias(self.alias) : a
end
end
end
diff --git a/spec/active_relation/integration/scratch_spec.rb b/spec/active_relation/integration/scratch_spec.rb
index cd4b4cd004..6aa27bc1fe 100644
--- a/spec/active_relation/integration/scratch_spec.rb
+++ b/spec/active_relation/integration/scratch_spec.rb
@@ -40,7 +40,7 @@ describe 'ActiveRelation', 'A proposed refactoring to ActiveRecord, introducing
@photos = Photo.relation
@cameras = Camera.relation
# A first taste of a Relational Algebra: User.find(1)
- @user = @users.select(@users[:id] == 1)
+ @user = @users.select(@users[:id].equals(1))
# == is overridden on attributes to return a predicate, not true or false
end
@@ -51,14 +51,14 @@ describe 'ActiveRelation', 'A proposed refactoring to ActiveRecord, introducing
primary_key = User.reflections[:photos].klass.primary_key.to_sym
foreign_key = User.reflections[:photos].primary_key_name.to_sym
- user_relation.outer_join(@photos).on(user_relation[primary_key] == @photos[foreign_key])
+ user_relation.outer_join(@photos).on(user_relation[primary_key].equals(@photos[foreign_key]))
end
def photo_belongs_to_camera(photo_relation)
primary_key = Photo.reflections[:camera].klass.primary_key.to_sym
foreign_key = Photo.reflections[:camera].primary_key_name.to_sym
- photo_relation.outer_join(@cameras).on(photo_relation[foreign_key] == @cameras[primary_key])
+ photo_relation.outer_join(@cameras).on(photo_relation[foreign_key].equals(@cameras[primary_key]))
end
describe 'Relational Algebra', 'a relational algebra allows the implementation of
@@ -184,7 +184,7 @@ describe 'ActiveRelation', 'A proposed refactoring to ActiveRecord, introducing
end
class Person < ActiveRecord::Base
- set_relation @accounts.join(@profiles).on(@accounts[:id] == @profiles[:account_id])
+ set_relation @accounts.join(@profiles).on(@accounts[:id].equals(@profiles[:account_id]))
end
# I know this sounds crazy, but even writes are possible in the last example.
# calling #save on a person can write to two tables!
diff --git a/spec/active_relation/relations/attribute_spec.rb b/spec/active_relation/relations/attribute_spec.rb
index 0c79e13b93..28fb0c3754 100644
--- a/spec/active_relation/relations/attribute_spec.rb
+++ b/spec/active_relation/relations/attribute_spec.rb
@@ -24,11 +24,11 @@ describe ActiveRelation::Primitives::Attribute do
end
end
- describe '#eql?' do
+ describe '==' do
it "obtains if the relation and attribute name are identical" do
- ActiveRelation::Primitives::Attribute.new(@relation1, :name).should be_eql(ActiveRelation::Primitives::Attribute.new(@relation1, :name))
- ActiveRelation::Primitives::Attribute.new(@relation1, :name).should_not be_eql(ActiveRelation::Primitives::Attribute.new(@relation1, :another_name))
- ActiveRelation::Primitives::Attribute.new(@relation1, :name).should_not be_eql(ActiveRelation::Primitives::Attribute.new(@relation2, :name))
+ ActiveRelation::Primitives::Attribute.new(@relation1, :name).should == ActiveRelation::Primitives::Attribute.new(@relation1, :name)
+ ActiveRelation::Primitives::Attribute.new(@relation1, :name).should_not == ActiveRelation::Primitives::Attribute.new(@relation1, :another_name)
+ ActiveRelation::Primitives::Attribute.new(@relation1, :name).should_not == ActiveRelation::Primitives::Attribute.new(@relation2, :name)
end
end
@@ -38,39 +38,39 @@ describe ActiveRelation::Primitives::Attribute do
@attribute2 = ActiveRelation::Primitives::Attribute.new(@relation2, :name)
end
- describe '==' do
+ describe '#equals' do
it "manufactures an equality predicate" do
- (@attribute1 == @attribute2).should == ActiveRelation::Predicates::Equality.new(@attribute1, @attribute2)
+ @attribute1.equals(@attribute2).should == ActiveRelation::Predicates::Equality.new(@attribute1, @attribute2)
end
end
- describe '<' do
+ describe '#less_than' do
it "manufactures a less-than predicate" do
- (@attribute1 < @attribute2).should == ActiveRelation::Predicates::LessThan.new(@attribute1, @attribute2)
+ @attribute1.less_than(@attribute2).should == ActiveRelation::Predicates::LessThan.new(@attribute1, @attribute2)
end
end
- describe '<=' do
+ describe '#less_than_or_equal_to' do
it "manufactures a less-than or equal-to predicate" do
- (@attribute1 <= @attribute2).should == ActiveRelation::Predicates::LessThanOrEqualTo.new(@attribute1, @attribute2)
+ @attribute1.less_than_or_equal_to(@attribute2).should == ActiveRelation::Predicates::LessThanOrEqualTo.new(@attribute1, @attribute2)
end
end
- describe '>' do
+ describe 'greater_than' do
it "manufactures a greater-than predicate" do
- (@attribute1 > @attribute2).should == ActiveRelation::Predicates::GreaterThan.new(@attribute1, @attribute2)
+ @attribute1.greater_than(@attribute2).should == ActiveRelation::Predicates::GreaterThan.new(@attribute1, @attribute2)
end
end
- describe '>=' do
+ describe '#greater_than_or_equal_to' do
it "manufactures a greater-than or equal to predicate" do
- (@attribute1 >= @attribute2).should == ActiveRelation::Predicates::GreaterThanOrEqualTo.new(@attribute1, @attribute2)
+ @attribute1.greater_than_or_equal_to(@attribute2).should == ActiveRelation::Predicates::GreaterThanOrEqualTo.new(@attribute1, @attribute2)
end
end
- describe '=~' do
+ describe '#matches' do
it "manufactures a match predicate" do
- (@attribute1 =~ /.*/).should == ActiveRelation::Predicates::Match.new(@attribute1, @attribute2)
+ @attribute1.matches(/.*/).should == ActiveRelation::Predicates::Match.new(@attribute1, @attribute2)
end
end
end