Sha256: f11adc6c3b2bd68a1c064234c657c1e0a0a9ffbe7e51f29fd33d483a53a3ec1a

Contents?: true

Size: 611 Bytes

Versions: 1

Compression:

Stored size: 611 Bytes

Contents

module Forewarn
  class TriggersWarning
    def trigger!(method, kaller)
      return if backtrace_includes_ourself?
      Forewarn.config[:logger].call(build_warning(method, kaller))
    end

  private

    # Need to bail out to prevent infinite recursion… Woo!
    def backtrace_includes_ourself?
      caller_locations.select { |location|
        location.to_s.include?(File.join(%w{forewarn lib forewarn triggers_warning}))
      }.size > 1
    end

    def build_warning(method, kaller)
      "WARN: #{method.warner.message} '#{method.name}' was invoked! (Called from: \"#{kaller}\")"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forewarn-0.1.0 lib/forewarn/triggers_warning.rb