aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-02-11 23:09:15 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-02-11 23:09:15 -0800
commit0d70ce37e510c83d5fc42f88b04314f40d87fe96 (patch)
tree03183df1b69ebb31bd5148bc8a9443647348ff3a
parent82cd330dbac31d79e23cc06273321ecbac2b9077 (diff)
downloadrails-0d70ce37e510c83d5fc42f88b04314f40d87fe96.tar.gz
rails-0d70ce37e510c83d5fc42f88b04314f40d87fe96.tar.bz2
rails-0d70ce37e510c83d5fc42f88b04314f40d87fe96.zip
rename substitute to bind since it 'binds' an object to a new relation.
-rw-r--r--lib/active_relation/extensions/object.rb2
-rw-r--r--lib/active_relation/predicates.rb4
-rw-r--r--lib/active_relation/primitives/attribute.rb2
-rw-r--r--lib/active_relation/primitives/expression.rb4
-rw-r--r--lib/active_relation/relations/aggregation.rb2
-rw-r--r--lib/active_relation/relations/compound.rb2
-rw-r--r--lib/active_relation/relations/join.rb4
-rw-r--r--lib/active_relation/relations/rename.rb6
-rw-r--r--spec/active_relation/predicates/binary_spec.rb6
-rw-r--r--spec/active_relation/primitives/attribute_spec.rb8
-rw-r--r--spec/active_relation/primitives/expression_spec.rb8
-rw-r--r--spec/active_relation/relations/compound_spec.rb12
-rw-r--r--spec/active_relation/relations/join_spec.rb2
-rw-r--r--spec/active_relation/relations/rename_spec.rb24
14 files changed, 43 insertions, 43 deletions
diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb
index 1db4c845be..35ffa9c661 100644
--- a/lib/active_relation/extensions/object.rb
+++ b/lib/active_relation/extensions/object.rb
@@ -3,7 +3,7 @@ class Object
self
end
- def substitute(relation)
+ def bind(relation)
self
end
diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb
index 54cc1fa5a0..76288595dc 100644
--- a/lib/active_relation/predicates.rb
+++ b/lib/active_relation/predicates.rb
@@ -20,8 +20,8 @@ module ActiveRelation
self.class.new(attribute.qualify, operand.qualify)
end
- def substitute(relation)
- self.class.new(attribute.substitute(relation), operand.substitute(relation))
+ def bind(relation)
+ self.class.new(attribute.bind(relation), operand.bind(relation))
end
def to_sql(strategy = Sql::Predicate.new)
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb
index 893feefef2..de25a90868 100644
--- a/lib/active_relation/primitives/attribute.rb
+++ b/lib/active_relation/primitives/attribute.rb
@@ -15,7 +15,7 @@ module ActiveRelation
Attribute.new(relation, name, aliaz, self)
end
- def substitute(new_relation)
+ def bind(new_relation)
relation == new_relation ? self : Attribute.new(new_relation, name, @alias, self)
end
diff --git a/lib/active_relation/primitives/expression.rb b/lib/active_relation/primitives/expression.rb
index ff07c40109..6ff06c7f81 100644
--- a/lib/active_relation/primitives/expression.rb
+++ b/lib/active_relation/primitives/expression.rb
@@ -10,8 +10,8 @@ module ActiveRelation
end
module Transformations
- def substitute(new_relation)
- new_relation == relation ? self : Expression.new(attribute.substitute(new_relation), function_sql, @alias, self)
+ def bind(new_relation)
+ new_relation == relation ? self : Expression.new(attribute.bind(new_relation), function_sql, @alias, self)
end
def as(aliaz)
diff --git a/lib/active_relation/relations/aggregation.rb b/lib/active_relation/relations/aggregation.rb
index 692a922ca7..9e803b3587 100644
--- a/lib/active_relation/relations/aggregation.rb
+++ b/lib/active_relation/relations/aggregation.rb
@@ -18,7 +18,7 @@ module ActiveRelation
end
def attributes
- expressions.collect { |e| e.substitute(self) }
+ expressions.collect { |e| e.bind(self) }
end
protected
diff --git a/lib/active_relation/relations/compound.rb b/lib/active_relation/relations/compound.rb
index befb7f26d2..d11d09fbf6 100644
--- a/lib/active_relation/relations/compound.rb
+++ b/lib/active_relation/relations/compound.rb
@@ -6,7 +6,7 @@ module ActiveRelation
:to => :relation
def attributes
- relation.attributes.collect { |a| a.substitute(self) }
+ relation.attributes.collect { |a| a.bind(self) }
end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb
index be2e89dd82..6d59ffcf39 100644
--- a/lib/active_relation/relations/join.rb
+++ b/lib/active_relation/relations/join.rb
@@ -24,7 +24,7 @@ module ActiveRelation
[
relation1.aggregation?? relation1.attributes.collect(&:to_attribute) : relation1.attributes,
relation2.aggregation?? relation2.attributes.collect(&:to_attribute) : relation2.attributes,
- ].flatten.collect { |a| a.substitute(self) }
+ ].flatten.collect { |a| a.bind(self) }
end
def prefix_for(attribute)
@@ -52,7 +52,7 @@ module ActiveRelation
private
def join
- [join_sql, right_table_sql, "ON", predicates.collect { |p| p.substitute(self).to_sql(Sql::Predicate.new) }.join(' AND ')].join(" ")
+ [join_sql, right_table_sql, "ON", predicates.collect { |p| p.bind(self).to_sql(Sql::Predicate.new) }.join(' AND ')].join(" ")
end
def right_table_sql
diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb
index 83ab41df70..6b1b29bf75 100644
--- a/lib/active_relation/relations/rename.rb
+++ b/lib/active_relation/relations/rename.rb
@@ -19,12 +19,12 @@ module ActiveRelation
end
def attributes
- relation.attributes.collect(&method(:substitute))
+ relation.attributes.collect(&method(:baptize))
end
private
- def substitute(attribute)
- (attribute =~ self.attribute ? attribute.as(pseudonym) : attribute).substitute(self) rescue nil
+ def baptize(attribute)
+ (attribute =~ self.attribute ? attribute.as(pseudonym) : attribute).bind(self) rescue nil
end
end
end \ No newline at end of file
diff --git a/spec/active_relation/predicates/binary_spec.rb b/spec/active_relation/predicates/binary_spec.rb
index 5d1e7d1223..599cfa2942 100644
--- a/spec/active_relation/predicates/binary_spec.rb
+++ b/spec/active_relation/predicates/binary_spec.rb
@@ -33,10 +33,10 @@ module ActiveRelation
end
end
- describe '#substitute' do
+ describe '#bind' do
it "distributes over the predicates and attributes" do
- ConcreteBinary.new(@attribute1, @attribute2).substitute(@relation2). \
- should == ConcreteBinary.new(@attribute1.substitute(@relation2), @attribute2.substitute(@relation2))
+ ConcreteBinary.new(@attribute1, @attribute2).bind(@relation2). \
+ should == ConcreteBinary.new(@attribute1.bind(@relation2), @attribute2.bind(@relation2))
end
end
diff --git a/spec/active_relation/primitives/attribute_spec.rb b/spec/active_relation/primitives/attribute_spec.rb
index e79f0c994d..ecc9014658 100644
--- a/spec/active_relation/primitives/attribute_spec.rb
+++ b/spec/active_relation/primitives/attribute_spec.rb
@@ -17,14 +17,14 @@ module ActiveRelation
end
end
- describe '#substitute' do
- it "manufactures an attribute with the relation substituted and self as an ancestor" do
+ describe '#bind' do
+ it "manufactures an attribute with the relation bindd and self as an ancestor" do
derived_relation = @relation.select(@relation[:id].equals(1))
- @attribute.substitute(derived_relation).should == Attribute.new(derived_relation, @attribute.name, nil, @attribute)
+ @attribute.bind(derived_relation).should == Attribute.new(derived_relation, @attribute.name, nil, @attribute)
end
it "returns self if the substituting to the same relation" do
- @attribute.substitute(@relation).should == @attribute
+ @attribute.bind(@relation).should == @attribute
end
end
diff --git a/spec/active_relation/primitives/expression_spec.rb b/spec/active_relation/primitives/expression_spec.rb
index d699dfded0..2ec5130386 100644
--- a/spec/active_relation/primitives/expression_spec.rb
+++ b/spec/active_relation/primitives/expression_spec.rb
@@ -12,14 +12,14 @@ module ActiveRelation
@expression = Expression.new(@attribute, "COUNT")
end
- describe '#substitute' do
- it "manufactures an attribute with a substituted relation and self as the ancestor" do
+ describe '#bind' do
+ it "manufactures an attribute with a bindd relation and self as the ancestor" do
derived_relation = @relation.select(@relation[:id] == 1)
- @expression.substitute(derived_relation).should == Expression.new(@attribute.substitute(derived_relation), "COUNT", nil, @expression)
+ @expression.bind(derived_relation).should == Expression.new(@attribute.bind(derived_relation), "COUNT", nil, @expression)
end
it "returns self if the substituting to the same relation" do
- @expression.substitute(@relation).should == @expression
+ @expression.bind(@relation).should == @expression
end
end
diff --git a/spec/active_relation/relations/compound_spec.rb b/spec/active_relation/relations/compound_spec.rb
index 79ac965e63..bb2919a318 100644
--- a/spec/active_relation/relations/compound_spec.rb
+++ b/spec/active_relation/relations/compound_spec.rb
@@ -14,21 +14,21 @@ module ActiveRelation
describe '#attributes' do
it 'manufactures attributes associated with the compound relation' do
- @compound_relation.attributes.should == @relation.attributes.collect { |a| a.substitute(@compound_relation) }
+ @compound_relation.attributes.should == @relation.attributes.collect { |a| a.bind(@compound_relation) }
end
end
describe '[]' do
describe 'when given a', Symbol do
it 'manufactures attributes associated with the compound relation if the symbol names an attribute within the relation' do
- @compound_relation[:id].should == @relation[:id].substitute(@compound_relation)
+ @compound_relation[:id].should == @relation[:id].bind(@compound_relation)
@compound_relation[:does_not_exist].should be_nil
end
end
describe 'when given an', Attribute do
- it "manufactures a substituted attribute when given an attribute within the relation" do
- @compound_relation[@relation[:id]].should == @relation[:id].substitute(@compound_relation)
+ it "manufactures a bindd attribute when given an attribute within the relation" do
+ @compound_relation[@relation[:id]].should == @relation[:id].bind(@compound_relation)
@compound_relation[@compound_relation[:id]].should == @compound_relation[:id]
pending "test nil"
end
@@ -42,8 +42,8 @@ module ActiveRelation
@compound_relation = ConcreteCompound.new(@nested_relation)
end
- it "manufactures a substituted Expression when given an Expression within the relation" do
- @compound_relation[@nested_expression].should == @nested_relation[@nested_expression].substitute(@compound_relation)
+ it "manufactures a bindd Expression when given an Expression within the relation" do
+ @compound_relation[@nested_expression].should == @nested_relation[@nested_expression].bind(@compound_relation)
@compound_relation[@compound_relation[@expression]].should == @compound_relation[@expression]
@compound_relation[@unprojected_expression].should be_nil
end
diff --git a/spec/active_relation/relations/join_spec.rb b/spec/active_relation/relations/join_spec.rb
index 3b2ad88123..5c86c72a18 100644
--- a/spec/active_relation/relations/join_spec.rb
+++ b/spec/active_relation/relations/join_spec.rb
@@ -40,7 +40,7 @@ module ActiveRelation
it 'combines the attributes of the two relations' do
@join.attributes.should ==
- (@relation1.attributes + @relation2.attributes).collect { |a| a.substitute(@join) }
+ (@relation1.attributes + @relation2.attributes).collect { |a| a.bind(@join) }
end
end
diff --git a/spec/active_relation/relations/rename_spec.rb b/spec/active_relation/relations/rename_spec.rb
index 695e51c191..5a6cecc39e 100644
--- a/spec/active_relation/relations/rename_spec.rb
+++ b/spec/active_relation/relations/rename_spec.rb
@@ -34,22 +34,22 @@ module ActiveRelation
describe 'when given a', Symbol do
it 'indexes attributes by rename if the symbol names an attribute within the relation' do
@renamed_relation[:id].should be_nil
- @renamed_relation[:schmid].should == @relation1[:id].as(:schmid).substitute(@renamed_relation)
+ @renamed_relation[:schmid].should == @relation1[:id].as(:schmid).bind(@renamed_relation)
@renamed_relation[:does_not_exist].should be_nil
end
end
describe 'when given an', Attribute do
- it 'manufactures a substituted and renamed attribute if the attribute is within the relation' do
- @renamed_relation[@relation1[:id]].should == @relation1[:id].as(:schmid).substitute(@renamed_relation)
- @renamed_relation[@relation1[:name]].should == @relation1[:name].substitute(@renamed_relation)
+ it 'manufactures a bindd and renamed attribute if the attribute is within the relation' do
+ @renamed_relation[@relation1[:id]].should == @relation1[:id].as(:schmid).bind(@renamed_relation)
+ @renamed_relation[@relation1[:name]].should == @relation1[:name].bind(@renamed_relation)
@renamed_relation[@renamed_relation[:name]].should == @renamed_relation[:name]
@renamed_relation[@relation2[:id]].should be_nil
end
end
describe 'when given an', Expression do
- it "manufactures a substituted and renamed expression if the expression is within the relation" do
+ it "manufactures a bindd and renamed expression if the expression is within the relation" do
pending
end
end
@@ -60,17 +60,17 @@ module ActiveRelation
end
describe 'when given a', Symbol do
- it 'manufactures a substituted and renamed attribute if the attribute is within the relation' do
+ it 'manufactures a bindd and renamed attribute if the attribute is within the relation' do
@renamed_renamed_relation[:id].should be_nil
@renamed_renamed_relation[:schmid].should be_nil
- @renamed_renamed_relation[:flid].should == @renamed_relation[:schmid].as(:flid).substitute(@renamed_renamed_relation)
+ @renamed_renamed_relation[:flid].should == @renamed_relation[:schmid].as(:flid).bind(@renamed_renamed_relation)
end
end
describe 'when given an', Attribute do
- it "manufactures a substituted and renamed attribute if the attribute is within the relation -- even if the provided attribute derived" do
- @renamed_renamed_relation[@renamed_relation[:schmid]].should == @renamed_relation[:schmid].as(:flid).substitute(@renamed_renamed_relation)
- @renamed_renamed_relation[@relation1[:id]].should == @renamed_relation[:schmid].as(:flid).substitute(@renamed_renamed_relation)
+ it "manufactures a bindd and renamed attribute if the attribute is within the relation -- even if the provided attribute derived" do
+ @renamed_renamed_relation[@renamed_relation[:schmid]].should == @renamed_relation[:schmid].as(:flid).bind(@renamed_renamed_relation)
+ @renamed_renamed_relation[@relation1[:id]].should == @renamed_relation[:schmid].as(:flid).bind(@renamed_renamed_relation)
end
end
@@ -81,8 +81,8 @@ module ActiveRelation
@renamed_relation = Rename.new(@aggregation, @expression => :cnt)
end
- it "manufactures a substituted and renamed expression if the expression is within the relation" do
- @renamed_relation[@expression].should == @aggregation[@expression].as(:cnt).substitute(@renamed_relation)
+ it "manufactures a bindd and renamed expression if the expression is within the relation" do
+ @renamed_relation[@expression].should == @aggregation[@expression].as(:cnt).bind(@renamed_relation)
end
end
end