uncruft 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c608624f22e89cb234de45de1a3247c70f0282b22725a6d214bc4c9dd8582dd
4
- data.tar.gz: 9597fc8b80850971a68b64791e331cd10ae1c74362de9a6c7e4fa646886c4fb9
3
+ metadata.gz: b7438d7362fc0084592b5bee3b2e2f36e48ad824a61b9ae39decad086d339527
4
+ data.tar.gz: 7c5d6e1cf564fd51df31b0b6562ccf5e92dc68d6a482341bc364f1698d045673
5
5
  SHA512:
6
- metadata.gz: e954a2ef6610cbefaa31d9eca450bc77797b67b4ea7e976165e75911f1a496a60ac0d1207b6ca78979ec3dbc5d210d4b8f7f6165413ff32be5364f4e63418184
7
- data.tar.gz: 703afa875346fd2b792886808920b00300ad38258738bcacf451a046edf22e441017d9d88c6ab055e1905b8ad6c2d006b6320852bd5520a0ce687774eb7a231b
6
+ metadata.gz: 753a2bbf179895c6f71c156bbf5dae6d3740c8b8988a21f4ee9b46a776434d8733a945be63e23b305e9073d2fc306d4dde4e77ab9c3ee162a29ad03fa63224c2
7
+ data.tar.gz: 0eb9160172952bf5977b2877c4d7e31e0a0442e6bbb5d7c25105bc1110710e28592f74aee63a53937ea268f9cf040f9e80c8a6115cc0304523165ae2f107177f
@@ -15,7 +15,10 @@ module Uncruft
15
15
 
16
16
  prepended_method.module_eval do
17
17
  define_method method do |*args, **kwargs, &block|
18
- Uncruft.deprecator.warn(message)
18
+ Uncruft.deprecator.warn(
19
+ message,
20
+ caller_locations(1).reject { |loc| loc.path.start_with?(Uncruft::GEM_ROOT) },
21
+ )
19
22
  super(*args, **kwargs, &block)
20
23
  end
21
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uncruft
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -4,11 +4,29 @@ module Uncruft
4
4
  module Warning
5
5
  DEPRECATION_PATTERN = /(deprecation|deprecated)/i
6
6
 
7
+ # Version-pinned: which internal frames are allowed at clocs[0].
8
+ # Empty array = no internal frames expected. Missing key = unknown combo.
9
+ EXPECTED_INTERNAL_FRAMES = {
10
+ ["3.2", "7.2"] => [],
11
+ ["3.2", "8.0"] => [],
12
+ ["3.3", "7.2"] => [],
13
+ ["3.3", "8.0"] => [],
14
+ ["3.4", "7.2"] => [],
15
+ ["3.4", "8.0"] => ['prism/polyfill/warn.rb'],
16
+ }.freeze
17
+
18
+ def self.expected_internal_frames
19
+ ruby_minor = RUBY_VERSION.split('.')[0..1].join('.')
20
+ rails_minor = Rails::VERSION::STRING.split('.')[0..1].join('.')
21
+ EXPECTED_INTERNAL_FRAMES[[ruby_minor, rails_minor]]
22
+ end
23
+
7
24
  def warn(*args, **kwargs)
8
25
  str = args[0]
9
26
 
10
27
  if str =~ DEPRECATION_PATTERN # rubocop:disable Performance/RegexpMatch
11
- message = strip_caller_info(str, caller_locations(1..1).first).strip
28
+ cloc = find_caller_location(caller_locations(1..5))
29
+ message = strip_caller_info(str, cloc).strip
12
30
  Uncruft.deprecator.warn(message)
13
31
  else
14
32
  super
@@ -17,6 +35,16 @@ module Uncruft
17
35
 
18
36
  private
19
37
 
38
+ def find_caller_location(clocs)
39
+ first = clocs.first
40
+ expected = Uncruft::Warning.expected_internal_frames
41
+ if first && expected&.any? { |pattern| first.path.include?(pattern) }
42
+ clocs[1] || first
43
+ else
44
+ first
45
+ end
46
+ end
47
+
20
48
  def strip_caller_info(str, cloc)
21
49
  str.sub(cloc.to_s, '') # try full caller information first
22
50
  .gsub(/#{cloc.path}(:#{cloc.lineno})?:?\s*/, '') # try path with optional line
data/lib/uncruft.rb CHANGED
@@ -10,6 +10,8 @@ require 'uncruft/deprecatable'
10
10
  require 'uncruft/warning'
11
11
 
12
12
  module Uncruft
13
+ GEM_ROOT = "#{File.expand_path('..', __dir__)}/".freeze
14
+
13
15
  class << self
14
16
  # http://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html
15
17
  FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uncruft
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Griffith
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.7.2
63
+ rubygems_version: 4.0.9
64
64
  specification_version: 4
65
65
  summary: A library to assist with Rails upgrades
66
66
  test_files: []