deprecations 2.2.2 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -11
- data/lib/deprecations/behavior.rb +20 -16
- data/lib/deprecations/extension.rb +56 -74
- data/lib/deprecations/version.rb +1 -1
- data/lib/deprecations.rb +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9973f05a62830c682760b9becfce855fa3e25d2bfdb40a0516846b5e3e27297f
|
4
|
+
data.tar.gz: 77b6ca73354da20235e652895d30513dc4f3ab47dd3bd73658eeb250d2cac52c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 190ddcd1b3f3f750d83579d369f02b12fc03f6fdd4a21a05b5d58a3d830d72b49c696bebbd8e27e431458a0224162a00bc1fa79f59851b608b5f9547b7e111ca
|
7
|
+
data.tar.gz: 14e17835fd8c727d3a30db5f22673918373969a4b687c494e67abe6b83e9f8e72ee0c6dcab98b63bca8e08926506e98c076e89a59acd9ae457787b42a01cd91b
|
data/README.md
CHANGED
@@ -14,13 +14,13 @@ gem 'deprecations'
|
|
14
14
|
|
15
15
|
and install it by running Bundler:
|
16
16
|
|
17
|
-
```
|
18
|
-
$ bundle
|
17
|
+
```shell
|
18
|
+
$ bundle add deprecations
|
19
19
|
```
|
20
20
|
|
21
21
|
To install the gem globally use:
|
22
22
|
|
23
|
-
```
|
23
|
+
```shell
|
24
24
|
$ gem install deprecations
|
25
25
|
```
|
26
26
|
|
@@ -36,7 +36,6 @@ you can specify which methods and classes are deprecated. To mark a method as de
|
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
class MySample
|
39
|
-
|
40
39
|
def clear
|
41
40
|
# something here
|
42
41
|
end
|
@@ -46,7 +45,6 @@ class MySample
|
|
46
45
|
end
|
47
46
|
|
48
47
|
deprecated :clean, :clear, 'next version'
|
49
|
-
|
50
48
|
end
|
51
49
|
```
|
52
50
|
|
@@ -79,9 +77,10 @@ There are 3 pre-defined behaviors:
|
|
79
77
|
Besides this you can implement your own:
|
80
78
|
|
81
79
|
```ruby
|
82
|
-
Deprecations.behavior =
|
83
|
-
|
84
|
-
|
80
|
+
Deprecations.behavior =
|
81
|
+
proc do |subject, _alternative, _outdated|
|
82
|
+
SuperLogger.warning "deprecated: #{subject}"
|
83
|
+
end
|
85
84
|
```
|
86
85
|
|
87
86
|
Any object responding to `#call` will be accepted as a valid handler.
|
@@ -89,9 +88,7 @@ Any object responding to `#call` will be accepted as a valid handler.
|
|
89
88
|
Whenever you need to temporary change the standard behavior (like e.g. in your specs) you can do this like
|
90
89
|
|
91
90
|
```ruby
|
92
|
-
Deprecations.with_behavior(:silent)
|
93
|
-
MyDeprecatedClass.new.do_some_magic
|
94
|
-
end
|
91
|
+
Deprecations.with_behavior(:silent) { MyDeprecatedClass.new.do_some_magic }
|
95
92
|
```
|
96
93
|
|
97
94
|
Please have a look at the [specs](https://github.com/mblumtritt/deprecations/blob/master/spec/deprecations_spec.rb) for detailed information and more samples.
|
@@ -14,12 +14,10 @@ module Deprecations
|
|
14
14
|
behavior = as_behavior(behavior)
|
15
15
|
raise(ArgumentError, 'block expected') unless block_given?
|
16
16
|
current_behavior = @behavior
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@behavior = current_behavior
|
22
|
-
end
|
17
|
+
@behavior = behavior
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
@behavior = current_behavior if current_behavior
|
23
21
|
end
|
24
22
|
|
25
23
|
alias set_behavior with_behavior
|
@@ -32,7 +30,7 @@ module Deprecations
|
|
32
30
|
raise(
|
33
31
|
ArgumentError,
|
34
32
|
'invalid parameter - behavior has to be ' \
|
35
|
-
"#{valid_behaviors} or need to respond to
|
33
|
+
"#{valid_behaviors} or need to respond to `#call`"
|
36
34
|
)
|
37
35
|
end
|
38
36
|
end
|
@@ -43,20 +41,26 @@ module Deprecations
|
|
43
41
|
|
44
42
|
module Raise
|
45
43
|
def self.call(subject, alternative, _outdated)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
raise(
|
45
|
+
Error
|
46
|
+
.new(
|
47
|
+
"`#{subject}` is deprecated#{
|
48
|
+
" - use #{alternative} instead" if alternative
|
49
|
+
}"
|
50
|
+
)
|
51
|
+
.tap { |error| error.set_backtrace(caller(3)) }
|
52
|
+
)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
56
|
module Warn
|
55
57
|
def self.call(subject, alternative, outdated)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
::Kernel.warn(
|
59
|
+
"`#{subject}` is deprecated#{
|
60
|
+
outdated ? " and will be outdated #{outdated}." : '.'
|
61
|
+
}#{" Please use `#{alternative}` instead." if alternative}",
|
62
|
+
uplevel: 3
|
63
|
+
)
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
@@ -1,93 +1,75 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Deprecations
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
mod.extend(ClassMethods)
|
9
|
-
mod.send(:include, InstanceMethods)
|
10
|
-
end
|
11
|
-
|
12
|
-
module Helper
|
13
|
-
private
|
4
|
+
private_class_method def self.infect(mod)
|
5
|
+
mod.extend(ClassMethods)
|
6
|
+
mod.__send__(:include, InstanceMethods)
|
7
|
+
end
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
instance_method(method_name)
|
18
|
-
rescue StandardError
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
end
|
9
|
+
module ClassMethods
|
10
|
+
private
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
12
|
+
def deprecated(method_name, alternative = nil, outdated = nil)
|
13
|
+
alias_name = "__deprecated__singleton_method__#{method_name}__"
|
14
|
+
return if private_method_defined?(alias_name)
|
15
|
+
alias_method(alias_name, method_name)
|
16
|
+
private(alias_name)
|
17
|
+
alternative = instance_method(alternative) if alternative.is_a?(Symbol)
|
18
|
+
define_method(method_name) do |*args, **kw_args, &b|
|
19
|
+
Deprecations.call(
|
20
|
+
"#{self}.#{::Kernel.__method__}",
|
21
|
+
if alternative.is_a?(UnboundMethod)
|
22
|
+
"#{self}.#{alternative.name}"
|
23
|
+
else
|
29
24
|
alternative
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
)
|
35
|
-
method.bind(self).call(*a, &b)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def __method_checked(method_name)
|
40
|
-
__method(method_name) or
|
41
|
-
raise(
|
42
|
-
NameError,
|
43
|
-
"undefined method `#{method_name}` for class `#{self}`"
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
def __method_alternative(alternative)
|
48
|
-
Symbol === alternative ? __method_checked(alternative) : alternative
|
25
|
+
end,
|
26
|
+
outdated
|
27
|
+
)
|
28
|
+
__send__(alias_name, *args, **kw_args, &b)
|
49
29
|
end
|
50
30
|
end
|
31
|
+
end
|
51
32
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
include Helper
|
33
|
+
module InstanceMethods
|
34
|
+
private
|
56
35
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
36
|
+
def deprecated(method_name, alternative = nil, outdated = nil)
|
37
|
+
alias_name = "__deprecated__instance_method__#{method_name}__"
|
38
|
+
return if private_method_defined?(alias_name)
|
39
|
+
alias_method(alias_name, method_name)
|
40
|
+
private(alias_name)
|
41
|
+
alternative = instance_method(alternative) if alternative.is_a?(Symbol)
|
42
|
+
define_method(method_name) do |*args, **kw_args, &b|
|
43
|
+
pref =
|
44
|
+
if defined?(self.class.name)
|
45
|
+
self.class.name
|
46
|
+
else
|
47
|
+
Kernel.instance_method(:class).bind(self).call
|
48
|
+
end
|
49
|
+
Deprecations.call(
|
50
|
+
"#{pref}##{::Kernel.__method__}",
|
51
|
+
if alternative.is_a?(UnboundMethod)
|
52
|
+
"#{pref}##{alternative.name}"
|
53
|
+
else
|
54
|
+
alternative
|
55
|
+
end,
|
61
56
|
outdated
|
62
57
|
)
|
58
|
+
__send__(alias_name, *args, **kw_args, &b)
|
63
59
|
end
|
60
|
+
rescue NameError
|
61
|
+
raise if private_method_defined?(alias_name)
|
62
|
+
singleton_class.__send__(:deprecated, method_name, alternative, outdated)
|
64
63
|
end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
def deprecated(method_name, alternative = nil, outdated = nil)
|
72
|
-
m = __method(method_name) or
|
73
|
-
return(
|
74
|
-
singleton_class.send(
|
75
|
-
:deprecated,
|
76
|
-
method_name,
|
77
|
-
alternative,
|
78
|
-
outdated
|
79
|
-
)
|
80
|
-
)
|
81
|
-
__method_deprecated!(m, __method_alternative(alternative), outdated)
|
82
|
-
end
|
83
|
-
|
84
|
-
def deprecated!(alternative = nil, outdated = nil)
|
85
|
-
m = method(:new)
|
86
|
-
define_singleton_method(:new) do |*a, &b|
|
87
|
-
Deprecations.call(self, alternative, outdated)
|
88
|
-
m.call(*a, &b)
|
89
|
-
end
|
65
|
+
def deprecated!(alternative = nil, outdated = nil)
|
66
|
+
org = method(:new)
|
67
|
+
define_singleton_method(:new) do |*args, **kw_args, &b|
|
68
|
+
Deprecations.call(name, alternative, outdated)
|
69
|
+
org.call(*args, **kw_args, &b)
|
90
70
|
end
|
71
|
+
rescue NameError
|
72
|
+
nil
|
91
73
|
end
|
92
74
|
end
|
93
75
|
|
data/lib/deprecations/version.rb
CHANGED
data/lib/deprecations.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Deprecations
|
4
|
-
require_relative 'deprecations/version'
|
5
|
-
require_relative 'deprecations/extension'
|
6
4
|
require_relative 'deprecations/behavior'
|
5
|
+
require_relative 'deprecations/extension'
|
6
|
+
require_relative 'deprecations/version'
|
7
7
|
|
8
8
|
Error = Class.new(ScriptError)
|
9
9
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deprecations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
This gem provides transparent declaration of deprecated methods and classes.
|
@@ -29,6 +29,7 @@ licenses: []
|
|
29
29
|
metadata:
|
30
30
|
source_code_uri: https://github.com/mblumtritt/deprecations
|
31
31
|
bug_tracker_uri: https://github.com/mblumtritt/deprecations/issues
|
32
|
+
rubygems_mfa_required: 'true'
|
32
33
|
post_install_message:
|
33
34
|
rdoc_options: []
|
34
35
|
require_paths:
|
@@ -37,14 +38,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
38
|
requirements:
|
38
39
|
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
41
|
+
version: 2.7.0
|
41
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
43
|
requirements:
|
43
44
|
- - ">="
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: '0'
|
46
47
|
requirements: []
|
47
|
-
rubygems_version: 3.
|
48
|
+
rubygems_version: 3.5.1
|
48
49
|
signing_key:
|
49
50
|
specification_version: 4
|
50
51
|
summary: Deprecation support for your project.
|