Sha256: c67c429d229b1ccdc371e3e415c151094b02f34d87a7e1c2c4f1d1533c918e36

Contents?: true

Size: 932 Bytes

Versions: 5

Compression:

Stored size: 932 Bytes

Contents

module WarningSigns
  class Deprecation
    attr_accessor :message, :source, :category, :backtrace

    def initialize(message, source:, category: nil, backtrace: [])
      @message = message
      @source = source.to_s.downcase.inquiry
      @category = category
      @backtrace = backtrace || []
    end

    def handler
      World.instance.handler_for(self)
    end

    def message_formatter_for(behavior)
      handler.message_formatter_for(behavior)
    end

    # force raise to be the last element if it is present
    def behaviors
      result = (handler&.environment&.behaviors || []).inquiry
      return result unless result.raise?
      (result - ["raise"]) << "raise"
    end

    def invoke
      behaviors.each do |behavior_type|
        Behavior::Base.for(
          behavior_type,
          message,
          backtrace,
          message_formatter_for(behavior_type)
        ).emit
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
warning_signs-0.7.2 lib/warning_signs/deprecation.rb
warning_signs-0.7.1 lib/warning_signs/deprecation.rb
warning_signs-0.7.0 lib/warning_signs/deprecation.rb
warning_signs-0.6.1 lib/warning_signs/deprecation.rb
warning_signs-0.6.0 lib/warning_signs/deprecation.rb