deprecation 0.2.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a2f81b6ac3b0ec0e588962e5c9b0314e7a8a3439
4
- data.tar.gz: b63ada54354a0804f77c468ade91442b5d82bb72
2
+ SHA256:
3
+ metadata.gz: e9a260ef95ae7ea900cdccf416399e8168e8da46ab3495addb20f104a3126657
4
+ data.tar.gz: 34417abfaf5f55051c0046f3b68a7deac496be50b79ebd750939305134a36f47
5
5
  SHA512:
6
- metadata.gz: a6b8a23cff2ad9efb77fcc4b5ec5d1b120239d2a3163108c97d5ae84241e668f9761253e034ceecc90aeffcb9842e831d477e8ec6b326da1feddfe6cc653086d
7
- data.tar.gz: 905c8692fa62dab1eaf683a42b288dab2246a615a258b80bfda4a273f22f97b5bead792f39ceea651ca026fe53fa917425029534f0c130f06ac7ab30970283c8
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
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  Deprecation
2
2
  ------------
3
- [![Build Status](https://travis-ci.org/cbeer/deprecation.png?branch=master)](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
+ ```
@@ -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
-
@@ -49,9 +49,6 @@ module Deprecation
49
49
  end
50
50
 
51
51
  included do
52
- class << self
53
- end
54
-
55
52
  # By default, warnings are not silenced and debugging is off.
56
53
  self.silenced = false
57
54
  self.debug = false
@@ -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
- target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
12
- target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
13
- def #{target}_with_deprecation#{punctuation}(*args, &block)
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
- send(:#{target}_without_deprecation#{punctuation}, *args, &block)
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
- deprecation_gem_root = File.expand_path("../..", __FILE__) + "/"
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
@@ -1,3 +1,3 @@
1
1
  module Deprecation
2
- VERSION = "0.2.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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.stub logger: logger
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.should_receive(:warn).with(/called from old_method/)
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: 0.2.0
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: 2015-02-19 00:00:00.000000000 Z
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: '0'
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
- rubyforge_project:
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
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - jruby-19mode