Sha256: fe310f85529b3527ad514cbd92dc2e9add107033aed90a87cbeed3ea0acee83f

Contents?: true

Size: 963 Bytes

Versions: 1

Compression:

Stored size: 963 Bytes

Contents

class Warning
  attr_accessor :message

  def initialize(message)
    self.message = message
  end

  module ClassMethods
    def active?
      disabled_warnings.all? {|w| !(w >= self)}
    end

    def disable
      if block_given?
        Dynamic.let(:disabled_warnings => disabled_warnings + [self]) do
          yield
        end
      else
        self.disabled_warnings += [self]
      end
    end

    def enable
      if block_given?
        Dynamic.let(:disabled_warnings => disabled_warnings - [self]) do
          yield
        end
      else
        self.disabled_warnings -= [self]
      end
    end

  protected
    def disabled_warnings
      Dynamic[:disabled_warnings]
    end
    def disabled_warnings=(new)
      Dynamic[:disabled_warnings] = new
    end
  end

  extend ClassMethods
end

class DeprecationWarning < Warning; end
class DeprecatedMethodWarning < DeprecationWarning; end
class DeprecatedSignatureWarning < DeprecationWarning; end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
structured_warnings-0.1.0 lib/structured_warnings/warning.rb