Sha256: fab9fb8fce4ad67a93f9706c2abaecec7471707e047fbb7664713b85d9ac59c6

Contents?: true

Size: 865 Bytes

Versions: 4

Compression:

Stored size: 865 Bytes

Contents

module Postmark
  def self.const_missing(const_name)
    replacement = Deprecations.deprecated_constants.fetch(const_name, nil) || super
    Deprecations.report("DEPRECATION WARNING: the class #{const_name} is deprecated. Use #{replacement} instead.")
    replacement
  end

  module Deprecations
    DEFAULT_BEHAVIORS = {
      :raise => lambda { |message| raise message },
      :log => lambda { |message| warn message },
      :silence => lambda { |message| },
    }

    def self.report(message)
      DEFAULT_BEHAVIORS.fetch(behavior).call(message)
    end

    def self.deprecated_constants
      @deprecated_constants ||= {}
    end

    def self.behavior
      @behavior ||= :log
    end

    def self.behavior=(behavior)
      @behavior = behavior
    end

    def self.add_constants(mappings)
      deprecated_constants.merge!(mappings)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
postmark-1.25.1 lib/postmark/deprecations.rb
postmark-1.25.0 lib/postmark/deprecations.rb
postmark-1.24.1 lib/postmark/deprecations.rb
postmark-1.24.0 lib/postmark/deprecations.rb