Sha256: 76f3f2fb410f19d1a4aaf1c07eb9da0f5647e3d9e21dd6cba2511c955dbab145

Contents?: true

Size: 1002 Bytes

Versions: 33

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

module Timezone
  # This class provides a way to set a custom hook for deprecations.
  module Deprecate
    class << self
      # Set the custom deprecation callback. By default this
      # issues a deprecation warning.
      #
      # @param callback [#call] the custom callback
      #
      # @example Send a message to StatsD
      #   Timezone::Deprecate.callback = lambda do |klass, method, _|
      #     StatsD.increment(sanitize(klass, method))
      #   end
      #
      # @example Send a message to a custom logger
      #   Timezone::Deprecate.callback = lambda do |klass, method, msg|
      #     MyLogger.log("[#{klass} : #{method}] #{msg}")
      #   end
      attr_writer :callback

      # @!visibility private
      def callback
        @callback || ->(_, _, message) { warn(message) }
      end

      # @!visibility private
      def call(klass, method, message)
        callback && callback.call(klass, method, message)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
timezone-1.3.28 lib/timezone/deprecate.rb
timezone-1.3.27 lib/timezone/deprecate.rb
timezone-1.3.26 lib/timezone/deprecate.rb
timezone-1.3.25 lib/timezone/deprecate.rb
timezone-1.3.24 lib/timezone/deprecate.rb
timezone-1.3.23 lib/timezone/deprecate.rb
timezone-1.3.22 lib/timezone/deprecate.rb
timezone-1.3.21 lib/timezone/deprecate.rb
timezone-1.3.20 lib/timezone/deprecate.rb
timezone-1.3.19 lib/timezone/deprecate.rb
timezone-1.3.18 lib/timezone/deprecate.rb
timezone-1.3.17 lib/timezone/deprecate.rb
timezone-1.3.16 lib/timezone/deprecate.rb
timezone-1.3.15 lib/timezone/deprecate.rb
timezone-1.3.14 lib/timezone/deprecate.rb
timezone-1.3.13 lib/timezone/deprecate.rb
timezone-1.3.12 lib/timezone/deprecate.rb
timezone-1.3.11 lib/timezone/deprecate.rb
timezone-1.3.10 lib/timezone/deprecate.rb
timezone-1.3.9 lib/timezone/deprecate.rb