lib/rails_current.rb in rails_current-1.6.2 vs lib/rails_current.rb in rails_current-1.7.0

- old
+ new

@@ -1,10 +1,10 @@ # -*- encoding : utf-8 -*- module Current def Current.version - '1.6.2' + '1.7.0' end def Current.dependencies { 'map' => [ 'map' , ' >= 6.0.1' ] @@ -20,11 +20,10 @@ Current.dependencies.each do |lib, dependency| gem(*dependency) if defined?(gem) require(lib) end - def Current.data Thread.current[:current] ||= Map.new end def Current.clear @@ -186,11 +185,11 @@ controller.request = request controller.response = response #controller.send(:initialize_template_class, response) #controller.send(:assign_shortcuts, request, response) controller.send(:default_url_options).merge!(default_url_options) - controller + Current.proxy_for(controller) end end def Current.ensure_rails_application(&block) require 'rails' unless defined?(Rails) @@ -204,10 +203,28 @@ end else block.call() end end + + class BlankSlate + instance_methods.each{|m| undef_method(m) unless m.to_s =~ /^__|object_id/} + end + + class Proxy < BlankSlate + def initialize(object) + @object = object + end + + def method_missing(method, *args, &block) + @object.__send__(method, *args, &block) + end + end + + def Current.proxy_for(object) + Proxy.new(object) + end end def Current(*args, &block) Current.attribute(*args, &block) end @@ -228,11 +245,11 @@ def Current.install_before_filter! if defined?(::ActionController::Base) ::ActionController::Base.module_eval do prepend_before_filter do |controller| Current.clear - Current.controller = controller - Current.action = controller.send(:action_name) + Current.controller = Current.proxy_for(controller) + Current.action = controller ? controller.send(:action_name) : nil end extend Current include Current helper{ include Current }