lib/influxer/metrics/scoping/current_scope.rb in influxer-1.3.0 vs lib/influxer/metrics/scoping/current_scope.rb in influxer-1.4.0

- old
+ new

@@ -1,8 +1,12 @@ # frozen_string_literal: true -require "active_support/per_thread_registry" +if Influxer.thread_registry_support? + require "active_support/per_thread_registry" +else + require "active_support/core_ext/module/delegation" +end module Influxer module Scoping module CurrentScope # :nodoc: # Clone of current_scope methods for newer versions of ActiveModel @@ -13,10 +17,20 @@ def current_scope=(scope) ScopeRegistry.set_value_for(:current_scope, name, scope) end class ScopeRegistry # :nodoc: - extend ActiveSupport::PerThreadRegistry + if Influxer.thread_registry_support? + extend ActiveSupport::PerThreadRegistry + else + class << self + delegate :value_for, :set_value_for, to: :instance + + def instance + ActiveSupport::IsolatedExecutionState[:influxer_scope_registry] ||= new + end + end + end VALID_SCOPE_TYPES = [:current_scope].freeze def initialize @registry = Hash.new { |hash, key| hash[key] = {} }