deprecations 2.2.0 → 2.2.2

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
2
  SHA256:
3
- metadata.gz: 9c5899644bd44226740f7c81c5b404d0bc942bbf256ecc47f540295bebab351a
4
- data.tar.gz: d5bfacd79de9a17bf16d8c6c95c29b0e1cc538bc975b188d73a515a0726aaf92
3
+ metadata.gz: 976d65184fd1442180e364ecd885aabf9202877f1bb7d11c1315eed9fe30b5ee
4
+ data.tar.gz: bf4ad1bc538b49878a6268321883d1d89a3cc3fe0627ef8c2d37200972c22ad2
5
5
  SHA512:
6
- metadata.gz: 0af667f71e7e2c2484114c00301cb44e1007ef7eae467fe3cdf6f00fa5011441078b29732a3f6a83a51a32af6409ba8ae772df1bb2b6bc1744768eed125d24da
7
- data.tar.gz: 0d2f21c5421992fd44110ae87fda1325eb16c946c692308fd3a51c5bbe86db86789905fbd4d71d325b152cbe1c9116ea796c04a08db100a2f6adff5ea1d47d4a
6
+ metadata.gz: 29383bc82baad099e0597f6efb0c4a0e2d4bb7f87e2235c19e1ebd58e0611c287aa7b1f478c1e75fc942f43bd2078cfb09f80f90df72ab4d184012e2dee8a51d
7
+ data.tar.gz: 0636b27fc0c83e46df73364b669b6c59f0c2e844e424807a990ee45d8bf1957b93db289d744d63013b099317f8f23618aa92b979c468a200712608956bd220a7
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Deprecations
2
4
  class << self
3
5
  def behavior
4
6
  BEHAVIOR.key(@behavior) || @behavior
5
7
  end
6
8
 
7
- def behavior=(behavior)
8
- @behavior = as_behavior(behavior)
9
+ def behavior=(value)
10
+ @behavior = as_behavior(value)
9
11
  end
10
12
 
11
13
  def with_behavior(behavior)
@@ -58,6 +60,6 @@ module Deprecations
58
60
  end
59
61
  end
60
62
 
61
- BEHAVIOR = {silence: proc {}, raise: Raise, warn: Warn}.freeze
63
+ BEHAVIOR = { silence: proc {}, raise: Raise, warn: Warn }.freeze
62
64
  end
63
65
  end
@@ -13,7 +13,11 @@ module Deprecations
13
13
  private
14
14
 
15
15
  def __method(method_name)
16
- instance_method(method_name) rescue nil
16
+ begin
17
+ instance_method(method_name)
18
+ rescue StandardError
19
+ nil
20
+ end
17
21
  end
18
22
 
19
23
  def __method_deprecated!(method, alternative, outdated)
@@ -21,16 +25,23 @@ module Deprecations
21
25
  undef_method(method.name)
22
26
  define_method(method.name) do |*a, &b|
23
27
  decorated = Class === self ? "#{self}." : "#{defining_context}#"
24
- alternative = "#{decorated}#{alternative.name}" if UnboundMethod === alternative
25
- Deprecations.call("#{decorated}#{::Kernel.__method__}", alternative, outdated)
28
+ alternative = "#{decorated}#{alternative.name}" if UnboundMethod ===
29
+ alternative
30
+ Deprecations.call(
31
+ "#{decorated}#{::Kernel.__method__}",
32
+ alternative,
33
+ outdated
34
+ )
26
35
  method.bind(self).call(*a, &b)
27
36
  end
28
37
  end
29
38
 
30
39
  def __method_checked(method_name)
31
- __method(method_name) or raise(
32
- NameError, "undefined method `#{method_name}` for class `#{self}`"
33
- )
40
+ __method(method_name) or
41
+ raise(
42
+ NameError,
43
+ "undefined method `#{method_name}` for class `#{self}`"
44
+ )
34
45
  end
35
46
 
36
47
  def __method_alternative(alternative)
@@ -58,9 +69,15 @@ module Deprecations
58
69
  include Helper
59
70
 
60
71
  def deprecated(method_name, alternative = nil, outdated = nil)
61
- m = __method(method_name) or return singleton_class.send(
62
- :deprecated, method_name, alternative, outdated
63
- )
72
+ m = __method(method_name) or
73
+ return(
74
+ singleton_class.send(
75
+ :deprecated,
76
+ method_name,
77
+ alternative,
78
+ outdated
79
+ )
80
+ )
64
81
  __method_deprecated!(m, __method_alternative(alternative), outdated)
65
82
  end
66
83
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deprecations
4
- VERSION = '2.2.0'
4
+ VERSION = '2.2.2'
5
5
  end
data/lib/deprecations.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Deprecations
2
4
  require_relative 'deprecations/version'
3
5
  require_relative 'deprecations/extension'
metadata CHANGED
@@ -1,84 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-19 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '1.10'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '1.10'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 10.1.1
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 10.1.1
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 3.0.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 3.0.0
11
+ date: 2022-07-30 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description: |
56
14
  This gem provides transparent declaration of deprecated methods and classes.
57
15
  It's easy, small, has no dependencies and no overhead.
58
- email: mike.blumtritt@invision.de
16
+ email:
59
17
  executables: []
60
18
  extensions: []
61
19
  extra_rdoc_files:
62
20
  - README.md
63
21
  files:
64
- - ".gitignore"
65
22
  - README.md
66
- - deprecations.gemspec
67
- - gems.rb
68
23
  - lib/deprecations.rb
69
24
  - lib/deprecations/behavior.rb
70
25
  - lib/deprecations/extension.rb
71
26
  - lib/deprecations/version.rb
72
- - rakefile.rb
73
- - spec/deprecations/behavior_spec.rb
74
- - spec/deprecations/version_spec.rb
75
- - spec/deprecations_spec.rb
76
- - spec/spec_helper.rb
77
27
  homepage: https://github.com/mblumtritt/deprecations
78
28
  licenses: []
79
29
  metadata:
80
- issue_tracker: https://github.com/mblumtritt/deprecations/issues
81
- post_install_message:
30
+ source_code_uri: https://github.com/mblumtritt/deprecations
31
+ bug_tracker_uri: https://github.com/mblumtritt/deprecations/issues
32
+ post_install_message:
82
33
  rdoc_options: []
83
34
  require_paths:
84
35
  - lib
@@ -91,15 +42,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
42
  requirements:
92
43
  - - ">="
93
44
  - !ruby/object:Gem::Version
94
- version: 1.10.0
45
+ version: '0'
95
46
  requirements: []
96
- rubyforge_project: deprecations
97
- rubygems_version: 2.7.7
98
- signing_key:
47
+ rubygems_version: 3.3.7
48
+ signing_key:
99
49
  specification_version: 4
100
50
  summary: Deprecation support for your project.
101
- test_files:
102
- - spec/deprecations/behavior_spec.rb
103
- - spec/deprecations/version_spec.rb
104
- - spec/deprecations_spec.rb
105
- - spec/spec_helper.rb
51
+ test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- tmp/
2
- local/
3
- diea/
4
- pkg/
5
- gems.locked
data/deprecations.gemspec DELETED
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './lib/deprecations/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = spec.rubyforge_project = 'deprecations'
7
- spec.version = Deprecations::VERSION
8
- spec.summary = 'Deprecation support for your project.'
9
- spec.description = <<~DESCRIPTION
10
- This gem provides transparent declaration of deprecated methods and classes.
11
- It's easy, small, has no dependencies and no overhead.
12
- DESCRIPTION
13
- spec.author = 'Mike Blumtritt'
14
- spec.email = 'mike.blumtritt@invision.de'
15
- spec.homepage = 'https://github.com/mblumtritt/deprecations'
16
- spec.metadata = {'issue_tracker' => 'https://github.com/mblumtritt/deprecations/issues'}
17
-
18
- spec.add_development_dependency 'bundler', '>= 1.10'
19
- spec.add_development_dependency 'rake', '>= 10.1.1'
20
- spec.add_development_dependency 'rspec', '>= 3.0.0'
21
-
22
- spec.platform = Gem::Platform::RUBY
23
- spec.required_ruby_version = '>= 2.0.0'
24
- spec.required_rubygems_version = Gem::Requirement.new('>= 1.10.0')
25
-
26
- spec.require_paths = %w[lib]
27
-
28
- all_files = %x(git ls-files -z).split(0.chr)
29
- spec.test_files = all_files.grep(%r{^(spec|test)/})
30
- spec.files = all_files - spec.test_files
31
-
32
- spec.extra_rdoc_files = %w[README.md]
33
- end
data/gems.rb DELETED
@@ -1 +0,0 @@
1
- source('https://rubygems.org'){ gemspec }
data/rakefile.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:test) do |t|
5
- t.pattern = ['spec/*_spec.rb', 'spec/**/*/*_spec.rb']
6
- t.rspec_opts = '-w'
7
- t.verbose = Rake.application.options.trace
8
- end
9
-
10
- task :default do
11
- exec "#{$0} --task"
12
- end
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Deprecations do
4
- context 'behavior' do
5
-
6
- it 'is possible to configure the behavior with a pre-defined value' do
7
- %i(silence raise warn).each do |behavior|
8
- Deprecations.behavior = behavior
9
- expect(Deprecations.behavior).to be(behavior)
10
- end
11
- end
12
-
13
- it 'is possible to configure a custom behavior' do
14
- custom = proc do |*args|
15
- FantasticLogger.log(*args)
16
- end
17
- Deprecations.behavior = custom
18
- expect(Deprecations.behavior).to be(custom)
19
- end
20
-
21
- context 'standard behavior :silence' do
22
- before do
23
- Deprecations.behavior = :silence
24
- end
25
-
26
- it 'does simply nothing' do
27
- expect(subject.call(*%w(should be silent))).to be(subject)
28
- end
29
- end
30
-
31
- context 'standard behavior :warn' do
32
- before do
33
- Deprecations.behavior = :warn
34
- end
35
- after do
36
- Deprecations.call('Bad#method', 'Bad#alternative', 'after next version')
37
- end
38
-
39
- it 'warns about the deprecation' do
40
- expect(Kernel).to receive(:warn).once.with(/.*/, uplevel: 3)
41
- end
42
-
43
- it 'points to the deprecated method' do
44
- expect(Kernel).to receive(:warn).once.with(/Bad#method.*deprecated/, uplevel: 3)
45
- end
46
-
47
- it 'suggests the alternative method' do
48
- expect(Kernel).to receive(:warn).once.with(/Bad#alternative.*instead/, uplevel: 3)
49
- end
50
-
51
- it 'contains information about when it will not longer supported' do
52
- expect(Kernel).to receive(:warn).once.with(/outdated after next version/, uplevel: 3)
53
- end
54
- end
55
-
56
- context 'standard behavior :raise' do
57
- before do
58
- Deprecations.behavior = :raise
59
- end
60
- subject{ Deprecations.call('Bad#method', 'Bad#alternative', 'after next version') }
61
-
62
- it 'raises a Deprecations::Error' do
63
- expect{ subject }.to raise_error(Deprecations::Error)
64
- end
65
-
66
- it 'points to the deprecated method' do
67
- expect{ subject }.to raise_error(Deprecations::Error, /Bad#method.*deprecated/)
68
- end
69
-
70
- it 'suggests the alternative method' do
71
- expect{ subject }.to raise_error(Deprecations::Error, /Bad#alternative.*instead/)
72
- end
73
- end
74
-
75
- context 'change behavior temporary' do
76
- let(:sample_class) do
77
- Class.new(BasicObject) do
78
- deprecated!
79
- end
80
- end
81
-
82
- before do
83
- Deprecations.behavior = :raise
84
- end
85
-
86
- after do
87
- Deprecations.with_behavior(:warn) do
88
- sample_class.new.__id__
89
- end
90
- end
91
-
92
- it 'is possible to temporary use a different behavior' do
93
- expect(Kernel).to receive(:warn).once
94
- end
95
- end
96
- end
97
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Deprecations::VERSION' do
4
- it 'has format <major>.<minor>.<build>' do
5
- expect(Deprecations::VERSION).to match(/^\d{1,2}\.\d{1,2}\.\d{1,3}/)
6
- end
7
- end
@@ -1,235 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Deprecations do
4
- context 'policy' do
5
- before do
6
- Deprecations.behavior = :silence
7
- end
8
-
9
- context 'parameter forwarding' do
10
-
11
- context 'when an instance method is marked as deprecated' do
12
- subject do
13
- Class.new(BasicObject) do
14
- def foo(*args)
15
- {foo: args}
16
- end
17
- deprecated :foo
18
- end
19
- end
20
-
21
- it 'forwards all parameters and returns the original method`s result' do
22
- result = subject.new.foo(:arg1, :arg2, 42)
23
- expect(result).to eq(foo: [:arg1, :arg2, 42])
24
- end
25
- end
26
-
27
- context 'when a class method is marked as deprecated' do
28
- subject do
29
- Class.new(BasicObject) do
30
- def self.foo(*args)
31
- {foo: args}
32
- end
33
- deprecated :foo
34
- end
35
- end
36
-
37
- it 'forwards all parameters and returns the original method`s result' do
38
- result = subject.foo(:arg1, :arg2, 42)
39
- expect(result).to eq(foo: [:arg1, :arg2, 42])
40
- end
41
- end
42
-
43
- context 'when a class is marked as deprecated' do
44
- subject do
45
- Class.new(BasicObject) do
46
- attr_reader :parameters
47
- def initialize(*parameters)
48
- @parameters = parameters
49
- end
50
- deprecated!
51
- end
52
- end
53
-
54
- it 'forwards all parameters to the initializer and returns the original method`s result' do
55
- expect(subject.new(:arg1, :arg2, 42).parameters).to eq([:arg1, :arg2, 42])
56
- end
57
- end
58
-
59
- end
60
-
61
- context 'block forwarding' do
62
-
63
- context 'when an instance method is marked as deprecated' do
64
- subject do
65
- Class.new(BasicObject) do
66
- def foo(arg)
67
- yield(arg)
68
- end
69
- deprecated :foo
70
- end
71
- end
72
-
73
- it 'forwards a given Proc to the original method' do
74
- result = subject.new.foo(41) do |arg|
75
- {my_blocks_result: arg + 1}
76
- end
77
- expect(result).to eq(my_blocks_result: 42)
78
- end
79
- end
80
-
81
- context 'when a class method is marked as deprecated' do
82
- subject do
83
- Class.new(BasicObject) do
84
- def self.foo(arg)
85
- yield(arg)
86
- end
87
- deprecated :foo
88
- end
89
- end
90
-
91
- it 'forwards a given Proc to the original method' do
92
- result = subject.foo(665) do |arg|
93
- {my_blocks_result: arg + 1}
94
- end
95
- expect(result).to eq(my_blocks_result: 666)
96
- end
97
- end
98
-
99
- context 'when a class is marked as deprecated' do
100
- subject do
101
- Class.new(BasicObject) do
102
- attr_reader :value
103
- def initialize(arg)
104
- @value = yield(arg)
105
- end
106
- deprecated!
107
- end
108
- end
109
-
110
- it 'forwards a given Proc to the initializer' do
111
- instance = subject.new(41) do |arg|
112
- {my_blocks_result: arg + 1}
113
- end
114
- expect(instance.value).to eq(my_blocks_result: 42)
115
- end
116
- end
117
-
118
- end
119
-
120
- end
121
-
122
- context 'handling' do
123
-
124
- context 'when a method is marked as deprecated' do
125
-
126
- context 'when an alternative method and a comment are present ' do
127
- subject do
128
- Class.new(BasicObject) do
129
- def foo
130
- end
131
- def bar
132
- end
133
- deprecated :foo, :bar, 'next version'
134
- end
135
- end
136
-
137
- after do
138
- subject.new.foo
139
- end
140
-
141
- it 'calls the handler with correct subject' do
142
- expect(Deprecations).to receive(:call)
143
- .once
144
- .with("#{subject}#foo", anything, anything)
145
- end
146
- it 'calls the handler with correct alternative method' do
147
- expect(Deprecations).to receive(:call)
148
- .once
149
- .with(anything, "#{subject}#bar", anything)
150
- end
151
- it 'calls the handler with a comment' do
152
- expect(Deprecations).to receive(:call)
153
- .once
154
- .with(anything, anything, 'next version')
155
- end
156
- end
157
-
158
- context 'when no alternative method and no comment are present' do
159
- subject do
160
- Class.new(BasicObject) do
161
- def bar
162
- end
163
- deprecated :bar
164
- end
165
- end
166
-
167
- after do
168
- subject.new.bar
169
- end
170
-
171
- it 'calls handler without an alternative method' do
172
- expect(Deprecations).to receive(:call).once.with(anything, nil, anything)
173
- end
174
- it 'calls handler without a comment' do
175
- expect(Deprecations).to receive(:call).once.with(anything, anything, nil)
176
- end
177
- end
178
-
179
- end
180
-
181
- context 'when a class is anonymous defined' do
182
- module Samples
183
- AnonymousDefined = Class.new(::BasicObject) do
184
- def clean; end
185
- def clear; end
186
- deprecated :clean, :clear
187
-
188
- def self.create; end
189
- def self.make; end
190
- deprecated :create, :make
191
- end
192
- end
193
-
194
- it 'uses correct decorated instance method names' do
195
- expect(Deprecations).to receive(:call).once.with(
196
- 'Samples::AnonymousDefined#clean',
197
- 'Samples::AnonymousDefined#clear',
198
- nil
199
- )
200
- Samples::AnonymousDefined.new.clean
201
- end
202
-
203
- it 'uses correct decorated singleton method names' do
204
- expect(Deprecations).to receive(:call).once.with(
205
- 'Samples::AnonymousDefined.create',
206
- 'Samples::AnonymousDefined.make',
207
- nil
208
- )
209
- Samples::AnonymousDefined.create
210
- end
211
- end
212
-
213
- context 'when a sub-class is used' do
214
- module Samples
215
- class Parent < ::BasicObject
216
- def clean; end
217
- def clear; end
218
- deprecated :clean, :clear
219
- end
220
-
221
- class Child < Parent; end
222
- end
223
-
224
- it 'uses correct decorated method names' do
225
- expect(Deprecations).to receive(:call).once.with(
226
- 'Samples::Parent#clean',
227
- 'Samples::Parent#clear',
228
- nil
229
- )
230
- Samples::Child.new.clean
231
- end
232
- end
233
-
234
- end
235
- end
data/spec/spec_helper.rb DELETED
@@ -1,8 +0,0 @@
1
- RSpec.configure do |config|
2
- config.raise_errors_for_deprecations!
3
- config.disable_monkey_patching!
4
- config.expose_dsl_globally = false
5
- config.expect_with(:rspec){ |c| c.syntax = :expect }
6
- config.mock_with(:rspec){ |c| c.syntax = :expect }
7
- end
8
- require 'deprecations'