deprecation 0.2.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 +5 -5
- data/.github/workflows/ruby.yml +31 -0
- data/Gemfile +1 -1
- data/README.md +1 -3
- data/deprecation.gemspec +2 -1
- data/lib/deprecation.rb +0 -3
- data/lib/deprecation/method_wrappers.rb +19 -4
- data/lib/deprecation/reporting.rb +11 -4
- data/lib/deprecation/version.rb +1 -1
- data/spec/deprecation_spec.rb +38 -7
- metadata +5 -6
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e9a260ef95ae7ea900cdccf416399e8168e8da46ab3495addb20f104a3126657
|
4
|
+
data.tar.gz: 34417abfaf5f55051c0046f3b68a7deac496be50b79ebd750939305134a36f47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13c2f5fd578288526c121533c676e4e29d1efa38c28d8f6de77807ee258a0a23c090bfbbdf4b2f55104c3885fb385f097da4cc83f9bd0ecae63f2e7ee3451abe
|
7
|
+
data.tar.gz: a8e27ab502a86737076f1decb8f7de57c8945a716adb64657692a618e394c8a39b5ba95f3816cd56fb3023d29f6dcf293089fb8fda2f15565bff20cc8cb8b779
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: CI
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby: [2.6, 2.7, 3.0]
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
- name: Install dependencies
|
29
|
+
run: bundle install
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rake
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
Deprecation
|
2
2
|
------------
|
3
|
-
[](https://travis-ci.org/cbeer/deprecation)
|
4
|
-
|
5
3
|
Provide deprecation warnings for code
|
6
4
|
|
7
5
|
## Add warnings
|
@@ -52,4 +50,4 @@ Deprecation.default_deprecation_behavior = :raise # Raise an exception when usin
|
|
52
50
|
|
53
51
|
Deprecation.default_deprecation_behavior = :silence # ignore all deprecations
|
54
52
|
|
55
|
-
```
|
53
|
+
```
|
data/deprecation.gemspec
CHANGED
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.homepage = "http://github.com/cbeer/deprecation"
|
13
13
|
s.license = "MIT"
|
14
14
|
|
15
|
+
s.required_ruby_version = '>= 2.1'
|
16
|
+
|
15
17
|
s.files = `git ls-files`.split("\n")
|
16
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -23,4 +25,3 @@ Gem::Specification.new do |s|
|
|
23
25
|
s.add_development_dependency "rspec", ">= 2.14"
|
24
26
|
s.add_development_dependency "bundler", ">= 1.0.14"
|
25
27
|
end
|
26
|
-
|
data/lib/deprecation.rb
CHANGED
@@ -7,20 +7,35 @@ module Deprecation
|
|
7
7
|
options = method_names.extract_options!
|
8
8
|
method_names += options.keys
|
9
9
|
|
10
|
+
generated_deprecation_methods = Module.new
|
10
11
|
method_names.each do |method_name|
|
11
|
-
|
12
|
-
|
13
|
-
def #{
|
12
|
+
if RUBY_VERSION < '3'
|
13
|
+
generated_deprecation_methods.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
|
14
|
+
def #{method_name}(*args, &block)
|
14
15
|
Deprecation.warn(#{target_module.to_s},
|
15
16
|
Deprecation.deprecated_method_warning(#{target_module.to_s},
|
16
17
|
:#{method_name},
|
17
18
|
#{options[method_name].inspect}),
|
18
19
|
caller
|
19
20
|
)
|
20
|
-
|
21
|
+
super
|
22
|
+
end
|
23
|
+
pass_keywords(:#{method_name}) if respond_to?(:pass_keywords, true)
|
24
|
+
end_eval
|
25
|
+
else
|
26
|
+
generated_deprecation_methods.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
|
27
|
+
def #{method_name}(*args, **kwargs, &block)
|
28
|
+
Deprecation.warn(#{target_module.to_s},
|
29
|
+
Deprecation.deprecated_method_warning(#{target_module.to_s},
|
30
|
+
:#{method_name},
|
31
|
+
#{options[method_name].inspect}),
|
32
|
+
caller
|
33
|
+
)
|
34
|
+
super
|
21
35
|
end
|
22
36
|
end_eval
|
23
37
|
end
|
24
38
|
end
|
39
|
+
target_module.prepend generated_deprecation_methods
|
25
40
|
end
|
26
41
|
end
|
@@ -18,7 +18,7 @@ module Deprecation
|
|
18
18
|
end
|
19
19
|
|
20
20
|
deprecation_message(callstack, message).tap do |m|
|
21
|
-
deprecation_behavior(context).each { |b| b.call(m, callstack) }
|
21
|
+
deprecation_behavior(context).each { |b| b.call(m, sanitized_callstack(callstack)) }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -62,7 +62,7 @@ module Deprecation
|
|
62
62
|
options = {}
|
63
63
|
end
|
64
64
|
|
65
|
-
warning = "#{method_name} is deprecated and will be removed from #{options[:deprecation_horizon] || context.deprecation_horizon}"
|
65
|
+
warning = "#{method_name} is deprecated and will be removed from #{options[:deprecation_horizon] || (context.deprecation_horizon if context.respond_to? :deprecation_horizon) || "a future release"}"
|
66
66
|
case message
|
67
67
|
when Symbol then "#{warning} (use #{message} instead)"
|
68
68
|
when String then "#{warning} (#{message})"
|
@@ -92,8 +92,7 @@ module Deprecation
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def extract_callstack(callstack)
|
95
|
-
|
96
|
-
offending_line = callstack.find { |line| !line.start_with?(deprecation_gem_root) and line !~ IGNORE_REGEX } || callstack.first
|
95
|
+
offending_line = sanitized_callstack(callstack).first || callstack.first
|
97
96
|
if offending_line
|
98
97
|
if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
|
99
98
|
md.captures
|
@@ -102,5 +101,13 @@ module Deprecation
|
|
102
101
|
end
|
103
102
|
end
|
104
103
|
end
|
104
|
+
|
105
|
+
def sanitized_callstack(callstack)
|
106
|
+
callstack.reject { |line| line.start_with? deprecation_gem_root}.select { |line| (line =~ IGNORE_REGEX).nil? }
|
107
|
+
end
|
108
|
+
|
109
|
+
def deprecation_gem_root
|
110
|
+
File.expand_path("../..", __FILE__) + "/"
|
111
|
+
end
|
105
112
|
end
|
106
113
|
end
|
data/lib/deprecation/version.rb
CHANGED
data/spec/deprecation_spec.rb
CHANGED
@@ -9,13 +9,13 @@ describe Deprecation do
|
|
9
9
|
|
10
10
|
|
11
11
|
def a
|
12
|
-
1
|
12
|
+
1
|
13
13
|
end
|
14
14
|
|
15
15
|
deprecation_deprecate :a
|
16
16
|
|
17
17
|
def b
|
18
|
-
|
18
|
+
|
19
19
|
end
|
20
20
|
|
21
21
|
def c
|
@@ -23,15 +23,21 @@ describe Deprecation do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def d
|
26
|
-
|
26
|
+
4
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
deprecation_deprecate :c, :d
|
30
30
|
|
31
31
|
def e
|
32
32
|
|
33
33
|
end
|
34
34
|
deprecation_deprecate :e => { :deprecation_horizon => 'asdf 1.4' }
|
35
|
+
|
36
|
+
|
37
|
+
def f(x, foo: nil)
|
38
|
+
7
|
39
|
+
end
|
40
|
+
deprecation_deprecate :f
|
35
41
|
end
|
36
42
|
subject { DeprecationTest.new}
|
37
43
|
|
@@ -41,6 +47,32 @@ describe Deprecation do
|
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
50
|
+
describe "a method that takes positional args and keyword args" do
|
51
|
+
around do |example|
|
52
|
+
# We need to suppress the raise behavior, so we can ensure the original method is called
|
53
|
+
DeprecationTest.deprecation_behavior = :silence
|
54
|
+
example.run
|
55
|
+
DeprecationTest.deprecation_behavior = :raise
|
56
|
+
end
|
57
|
+
|
58
|
+
it "delegates to the original" do
|
59
|
+
expect(subject.f 9, foo: 3).to eq 7
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "a method that takes no args" do
|
64
|
+
around do |example|
|
65
|
+
# We need to suppress the raise behavior, so we can ensure the original method is called
|
66
|
+
DeprecationTest.deprecation_behavior = :silence
|
67
|
+
example.run
|
68
|
+
DeprecationTest.deprecation_behavior = :raise
|
69
|
+
end
|
70
|
+
|
71
|
+
it "delegates to the original" do
|
72
|
+
expect(subject.d).to eq 4
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
44
76
|
describe "b" do
|
45
77
|
it "should not be deprecated" do
|
46
78
|
expect { subject.b }.not_to raise_error
|
@@ -90,12 +122,11 @@ describe Deprecation do
|
|
90
122
|
let(:logger) { double() }
|
91
123
|
|
92
124
|
before(:each) do
|
93
|
-
Deprecation.
|
94
|
-
Deprecation.stub default_deprecation_behavior: :log
|
125
|
+
allow(Deprecation).to receive_messages(logger: logger, default_deprecation_behavior: :log)
|
95
126
|
end
|
96
127
|
|
97
128
|
it "should provide a useful deprecation trace" do
|
98
|
-
logger.
|
129
|
+
expect(logger).to receive(:warn).with(/called from old_method/)
|
99
130
|
expect(A.new.old_method).to eq true
|
100
131
|
|
101
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deprecation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".github/workflows/ruby.yml"
|
76
77
|
- ".gitignore"
|
77
|
-
- ".travis.yml"
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE
|
80
80
|
- README.md
|
@@ -102,15 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: '
|
105
|
+
version: '2.1'
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.4.5
|
112
|
+
rubygems_version: 3.1.2
|
114
113
|
signing_key:
|
115
114
|
specification_version: 4
|
116
115
|
summary: Stand-alone deprecation library borrowed from ActiveSupport::Deprecation
|