Sha256: 2eefaa14912e86671a90421f2bd36498b25a519bb93dceba2b5cdcca31b36b50
Contents?: true
Size: 972 Bytes
Versions: 4
Compression:
Stored size: 972 Bytes
Contents
# frozen_string_literal: true module Uncruft module Warning DEPRECATION_PATTERN = /(deprecation|deprecated)/i def warn(*args, **kwargs) str = args[0] if str =~ DEPRECATION_PATTERN # rubocop:disable Performance/RegexpMatch message = strip_caller_info(str, caller_locations(1..1).first).strip Uncruft.deprecator.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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
uncruft-0.7.1 | lib/uncruft/warning.rb |
uncruft-0.7.0 | lib/uncruft/warning.rb |
uncruft-0.6.2 | lib/uncruft/warning.rb |
uncruft-0.6.1 | lib/uncruft/warning.rb |