Sha256: d0a542379a099c836e93c0875fc2b948343ea4c0c4722851d14bc3a27c875cef

Contents?: true

Size: 1.38 KB

Versions: 37

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  #
  # Class Deprecation provides logging of deprecations
  #
  # @author Mikael Henriksson <mikael@mhenrixon.com>
  #
  class Deprecation
    #
    # Mute warnings from this gem in a threaded context
    #
    #
    # @return [void] <description>
    #
    # @yieldreturn [void]
    def self.muted
      orig_val = Thread.current[:uniquejobs_mute_deprecations]
      Thread.current[:uniquejobs_mute_deprecations] = true
      yield
    ensure
      Thread.current[:uniquejobs_mute_deprecations] = orig_val
    end

    #
    # Check if deprecation warnings have been muted
    #
    #
    # @return [true,false]
    #
    def self.muted?
      Thread.current[:uniquejobs_mute_deprecations] == true
    end

    #
    # Warn about deprecation
    #
    # @param [String] msg a descriptive reason for why the deprecation
    #
    # @return [void]
    #
    def self.warn(msg)
      return if SidekiqUniqueJobs::Deprecation.muted?

      warn "DEPRECATION WARNING: #{msg}"
      nil
    end

    #
    # Warn about deprecation and provide a context
    #
    # @param [String] msg a descriptive reason for why the deprecation
    #
    # @return [void]
    #
    def self.warn_with_backtrace(msg)
      return if SidekiqUniqueJobs::Deprecation.muted?

      trace = "\n\nCALLED FROM:\n#{caller.join("\n")}"
      warn(msg + trace)

      nil
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.10 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.33 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.32 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.9 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.8 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.31 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.30 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.29 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.28 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.27 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.26 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.25 lib/sidekiq_unique_jobs/deprecation.rb