lib/ahoy/controller.rb in ahoy_matey-2.2.1 vs lib/ahoy/controller.rb in ahoy_matey-3.0.0
- old
+ new
@@ -1,17 +1,15 @@
-require "request_store"
-
module Ahoy
module Controller
def self.included(base)
if base.respond_to?(:helper_method)
base.helper_method :current_visit
base.helper_method :ahoy
end
base.before_action :set_ahoy_cookies, unless: -> { Ahoy.api_only }
base.before_action :track_ahoy_visit, unless: -> { Ahoy.api_only }
- base.before_action :set_ahoy_request_store
+ base.around_action :set_ahoy_request_store
end
def ahoy
@ahoy ||= Ahoy::Tracker.new(controller: self)
end
@@ -39,9 +37,15 @@
ahoy.track_visit(defer: defer)
end
end
def set_ahoy_request_store
- RequestStore.store[:ahoy] ||= ahoy
+ previous_value = Thread.current[:ahoy]
+ begin
+ Thread.current[:ahoy] = ahoy
+ yield
+ ensure
+ Thread.current[:ahoy] = previous_value
+ end
end
end
end