aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-08-06 08:58:58 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-08-06 08:58:58 -0700
commit4c43dac54e649f579a96505e0038cfb6ea52ef1e (patch)
treedde1ba4baec0e28ce241c2e4a17c987fcb40af62
parent1b62990cfa10feea7f3937bbcd2145adae84db85 (diff)
downloadrails-4c43dac54e649f579a96505e0038cfb6ea52ef1e.tar.gz
rails-4c43dac54e649f579a96505e0038cfb6ea52ef1e.tar.bz2
rails-4c43dac54e649f579a96505e0038cfb6ea52ef1e.zip
unfactoring more module inclusion
-rw-r--r--lib/arel/algebra/relations/relation.rb97
-rw-r--r--spec/algebra/unit/relations/relation_spec.rb2
2 files changed, 48 insertions, 51 deletions
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb
index de48aaf04e..e2f9f12866 100644
--- a/lib/arel/algebra/relations/relation.rb
+++ b/lib/arel/algebra/relations/relation.rb
@@ -102,75 +102,72 @@ module Arel
session.read(self).each { |e| yield e }
end
- module Operable
- def join(other_relation = nil, join_class = InnerJoin)
- case other_relation
- when String
- StringJoin.new(self, other_relation)
- when Relation
- JoinOperation.new(join_class, self, other_relation)
- else
- self
- end
+ def join(other_relation = nil, join_class = InnerJoin)
+ case other_relation
+ when String
+ StringJoin.new(self, other_relation)
+ when Relation
+ JoinOperation.new(join_class, self, other_relation)
+ else
+ self
end
+ end
- def outer_join(other_relation = nil)
- join(other_relation, OuterJoin)
- end
+ def outer_join(other_relation = nil)
+ join(other_relation, OuterJoin)
+ end
- %w{
+ %w{
having group order project
- }.each do |op|
- class_eval <<-OPERATION, __FILE__, __LINE__
+ }.each do |op|
+ class_eval <<-OPERATION, __FILE__, __LINE__
def #{op}(*args)
args.all? { |x| x.blank? } ? self : #{op.capitalize}.new(self, args)
end
- OPERATION
- end
+ OPERATION
+ end
- def where clause = nil
- clause ? Where.new(self, Array(clause)) : self
- end
+ def where clause = nil
+ clause ? Where.new(self, Array(clause)) : self
+ end
- def skip thing = nil
- thing ? Skip.new(self, thing) : self
- end
+ def skip thing = nil
+ thing ? Skip.new(self, thing) : self
+ end
- def take count
- Take.new self, count
- end
+ def take count
+ Take.new self, count
+ end
- def from thing
- From.new self, thing
- end
+ def from thing
+ From.new self, thing
+ end
- def lock(locking = true)
- Lock.new(self, locking)
- end
+ def lock(locking = true)
+ Lock.new(self, locking)
+ end
- def alias
- Alias.new(self)
- end
+ def alias
+ Alias.new(self)
+ end
- def insert(record)
- session.create Insert.new(self, record)
- end
+ def insert(record)
+ session.create Insert.new(self, record)
+ end
- def update(assignments)
- session.update Update.new(self, assignments)
- end
+ def update(assignments)
+ session.update Update.new(self, assignments)
+ end
- def delete
- session.delete Deletion.new(self)
- end
+ def delete
+ session.delete Deletion.new(self)
+ end
- JoinOperation = Struct.new(:join_class, :relation1, :relation2) do
- def on(*predicates)
- join_class.new(relation1, relation2, *predicates)
- end
+ JoinOperation = Struct.new(:join_class, :relation1, :relation2) do
+ def on(*predicates)
+ join_class.new(relation1, relation2, *predicates)
end
end
- include Operable
def [](index)
attributes[index]
diff --git a/spec/algebra/unit/relations/relation_spec.rb b/spec/algebra/unit/relations/relation_spec.rb
index 07a7dcb843..d08c38acd5 100644
--- a/spec/algebra/unit/relations/relation_spec.rb
+++ b/spec/algebra/unit/relations/relation_spec.rb
@@ -23,7 +23,7 @@ module Arel
end
end
- describe Relation::Operable do
+ describe 'Relation::Operable' do
describe 'joins' do
before do
@predicate = @relation[:id].eq(@relation[:id])