Sha256: 77c44c1a2baf0578b2fa12e6728b9c2a039e9891fd501b83a66a335f63043d28

Contents?: true

Size: 536 Bytes

Versions: 9

Compression:

Stored size: 536 Bytes

Contents

# frozen_string_literal: true

module ArLazyPreload
  module Contexts
    # Preload config that used to enable preloading only for specfic part of the application
    class TemporaryPreloadConfig
      THREAD_KEY = "temporary_preload_context_enabled"

      class << self
        def enabled?
          Thread.current[THREAD_KEY] == true
        end

        def within_context
          Thread.current[THREAD_KEY] = true
          yield
        ensure
          Thread.current[THREAD_KEY] = nil
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ar_lazy_preload-2.1.0 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-2.0.0 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-1.1.2 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-1.1.1 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-1.1.0 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-1.0.0 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-0.7.0 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-0.6.2 lib/ar_lazy_preload/contexts/temporary_preload_config.rb
ar_lazy_preload-0.6.1 lib/ar_lazy_preload/contexts/temporary_preload_config.rb