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-7.1.24 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.23 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.22 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.21 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.20 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.19 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.18 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.17 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.16 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.15 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.14 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.13 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.12 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.11 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.10 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.8 lib/sidekiq_unique_jobs/deprecation.rb
sidekiq-unique-jobs-7.1.7 lib/sidekiq_unique_jobs/deprecation.rb