aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-20 15:00:36 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-20 15:00:36 -0700
commit703571f7e0bebb3d2bd43a7af5976ad4565ac2cb (patch)
tree9bb33c0fc5c1fbd62b3457aa8c45726a59881a89 /lib
parent692566733e4442947c6b6faa2f5a1b13940744d0 (diff)
downloadrails-703571f7e0bebb3d2bd43a7af5976ad4565ac2cb.tar.gz
rails-703571f7e0bebb3d2bd43a7af5976ad4565ac2cb.tar.bz2
rails-703571f7e0bebb3d2bd43a7af5976ad4565ac2cb.zip
use Session.instance rather than Session.new for easier code
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/algebra/relations/relation.rb2
-rw-r--r--lib/arel/session.rb32
2 files changed, 9 insertions, 25 deletions
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb
index 0332482066..34181beea2 100644
--- a/lib/arel/algebra/relations/relation.rb
+++ b/lib/arel/algebra/relations/relation.rb
@@ -3,7 +3,7 @@ module Arel
attr_reader :count
def session
- Session.new
+ Session.instance
end
def call
diff --git a/lib/arel/session.rb b/lib/arel/session.rb
index e6da825b97..622ca090f8 100644
--- a/lib/arel/session.rb
+++ b/lib/arel/session.rb
@@ -1,30 +1,14 @@
module Arel
class Session
- class << self
- attr_accessor :instance
- alias_method :manufacture, :new
+ def self.instance
+ @instance || new
+ end
- def start
- if defined?(@started) && @started
- yield
- else
- begin
- @started = true
- @instance = manufacture
- singleton_class.class_eval do
- undef :new
- alias_method :new, :instance
- end
- yield
- ensure
- singleton_class.class_eval do
- undef :new
- alias_method :new, :manufacture
- end
- @started = false
- end
- end
- end
+ def self.start
+ @instance ||= new
+ yield @instance
+ ensure
+ @instance = nil
end
module CRUD