Sha256: 75a5e5b8d6946f2c1f28f4fe040f8fe07d2093775ef61fb53041add464230e2d

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

module Uncruft
  module Warning
    DEPRECATION_PATTERN = /(deprecation|deprecated)/i

    def warn(str, *args)
      if str =~ DEPRECATION_PATTERN # rubocop:disable Performance/RegexpMatch
        message = strip_caller_info(str, caller_locations(1..1).first).strip
        ActiveSupport::Deprecation.warn(message)
      else
        super
      end
    end

    private

    def strip_caller_info(str, cloc)
      str.sub(cloc.to_s, '') # try full caller information first
        .gsub(/#{cloc.path}(:#{cloc.lineno})?:?\s*/, '') # try path with optional line
    end
  end
end

if Rails.env.development? || Rails.env.test?
  if defined?(Warning)
    Warning.prepend(Uncruft::Warning)
    Warning.singleton_class.prepend(Uncruft::Warning)
  end
  Kernel.prepend(Uncruft::Warning)
  Kernel.singleton_class.prepend(Uncruft::Warning)
  Object.prepend(Uncruft::Warning)
  Object.singleton_class.prepend(Uncruft::Warning)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uncruft-0.0.2 lib/uncruft/warning.rb