deprecations 2.6.0 → 2.7.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 +4 -4
- data/README.md +22 -21
- data/deprecations.gemspec +26 -0
- data/lib/deprecations/version.rb +1 -1
- data/lib/deprecations.rb +99 -94
- metadata +14 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4cdbe0575ac1d02430ffc3e88c32688824d9ba47dbaaf3bc67608174a24e319
|
|
4
|
+
data.tar.gz: 22c9ed6e63fcdd3b6eb5fa287326e87e1bd7598a033748b7869d139c6c56be35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a7c9d6706072053a2c4fade7a96c7aa4c86c986d77cb71bbad346778b6c041fcc9a4e3cc1e57750bd081341f353e7c2069e5c16df8af81a8f5f9df682040f45
|
|
7
|
+
data.tar.gz: 1f8658e34eefb696079867af2e71534758ca0af650484d84b4249e797094d42e33587374764037b25daca616a97a2ebdbb8554e34ac3f95bcb5618d38f64d6a9
|
data/README.md
CHANGED
|
@@ -2,27 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This gem provides transparent declaration of deprecated methods and classes. It's easy, small, has no dependencies and no overhead.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
The simplest way to install Deprecations gem is to use [Bundler](http://gembundler.com/).
|
|
8
|
-
|
|
9
|
-
Add Deprecations to your `Gemfile`:
|
|
10
|
-
|
|
11
|
-
```ruby
|
|
12
|
-
gem 'deprecations'
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
and install it by running Bundler:
|
|
16
|
-
|
|
17
|
-
```shell
|
|
18
|
-
$ bundle add deprecations
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
To install the gem globally use:
|
|
22
|
-
|
|
23
|
-
```shell
|
|
24
|
-
$ gem install deprecations
|
|
25
|
-
```
|
|
5
|
+
- Gem: [rubygems.org](https://rubygems.org/gems/deprecations)
|
|
6
|
+
- Source: [codeberg.org](https://codeberg.org/mblumtritt/deprecations)
|
|
26
7
|
|
|
27
8
|
## Usage
|
|
28
9
|
|
|
@@ -93,3 +74,23 @@ Deprecations.with_behavior(:silent) { MyDeprecatedClass.new.do_some_magic }
|
|
|
93
74
|
```
|
|
94
75
|
|
|
95
76
|
Please have a look at the [specs](https://github.com/mblumtritt/deprecations/blob/master/spec/deprecations_spec.rb) for detailed information and more samples.
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
You can install the gem in your system with
|
|
81
|
+
|
|
82
|
+
```shell
|
|
83
|
+
gem install deprecations
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
or you can use [Bundler](http://gembundler.com/) to add Terminal.rb to your own project:
|
|
87
|
+
|
|
88
|
+
```shell
|
|
89
|
+
bundle add deprecations
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
After that you only need one line of code to have everything together
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
require 'deprecations'
|
|
96
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/deprecations/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'deprecations'
|
|
7
|
+
spec.version = Deprecations::VERSION
|
|
8
|
+
spec.summary = 'Deprecation support for your project.'
|
|
9
|
+
spec.description = <<~DESCRIPTION.tr("\n", ' ')
|
|
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
|
+
|
|
14
|
+
spec.author = 'Mike Blumtritt'
|
|
15
|
+
spec.licenses = %w[MIT Ruby]
|
|
16
|
+
spec.homepage = 'https://codeberg.org/mblumtritt/deprecations'
|
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
|
|
19
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
20
|
+
|
|
21
|
+
spec.required_ruby_version = '> 3.0'
|
|
22
|
+
|
|
23
|
+
spec.files = Dir['lib/**/*.rb']
|
|
24
|
+
spec.files += %w[deprecations.gemspec]
|
|
25
|
+
spec.extra_rdoc_files = %w[README.md]
|
|
26
|
+
end
|
data/lib/deprecations/version.rb
CHANGED
data/lib/deprecations.rb
CHANGED
|
@@ -13,8 +13,7 @@ module Deprecations
|
|
|
13
13
|
def with_behavior(behavior)
|
|
14
14
|
current_behavior = @behavior
|
|
15
15
|
@behavior = as_behavior(behavior)
|
|
16
|
-
|
|
17
|
-
yield
|
|
16
|
+
yield if block_given?
|
|
18
17
|
ensure
|
|
19
18
|
@behavior = current_behavior
|
|
20
19
|
end
|
|
@@ -44,125 +43,131 @@ module Deprecations
|
|
|
44
43
|
exc.set_backtrace(exc.backtrace.drop_while { _1.start_with?(__FILE__) })
|
|
45
44
|
exc
|
|
46
45
|
end
|
|
46
|
+
end
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
48
|
+
module Raise
|
|
49
|
+
def self.call(subject, alternative, _outdated)
|
|
50
|
+
error =
|
|
51
|
+
Error.new(
|
|
52
|
+
"`#{subject}` is deprecated#{
|
|
53
|
+
" - use #{alternative} instead" if alternative
|
|
54
|
+
}"
|
|
55
|
+
)
|
|
56
|
+
error.set_backtrace(caller(3))
|
|
57
|
+
raise(error)
|
|
59
58
|
end
|
|
59
|
+
end
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
end
|
|
61
|
+
module WarnMessage
|
|
62
|
+
def message(subject, alternative, outdated)
|
|
63
|
+
"`#{subject}` is deprecated#{
|
|
64
|
+
outdated ? " and will be outdated #{outdated}." : '.'
|
|
65
|
+
}#{" Please use `#{alternative}` instead." if alternative}"
|
|
67
66
|
end
|
|
67
|
+
end
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def self.call(*args) = ::Kernel.warn(message(*args), uplevel: 3)
|
|
72
|
-
end
|
|
69
|
+
module Warn
|
|
70
|
+
extend WarnMessage
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
def self.call(*args) = ::Kernel.warn(message(*args), uplevel: 3)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
module Deprecated
|
|
76
|
+
extend WarnMessage
|
|
77
|
+
|
|
78
|
+
def self.call(*args)
|
|
79
|
+
::Kernel.warn(message(*args), uplevel: 3, category: :deprecated)
|
|
79
80
|
end
|
|
81
|
+
end
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
BEHAVIOR = {
|
|
84
|
+
silence: proc {},
|
|
85
|
+
raise: Raise,
|
|
86
|
+
warn: Warn,
|
|
87
|
+
deprecated: Deprecated
|
|
88
|
+
}.freeze
|
|
87
89
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
module ClassMethods
|
|
91
|
+
private
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
def deprecated(name, alt = nil, outdated = nil)
|
|
94
|
+
alias_name = "__deprecated__singleton_method__#{name}__"
|
|
95
|
+
return if private_method_defined?(alias_name)
|
|
96
|
+
begin
|
|
97
|
+
alias_method(alias_name, name)
|
|
98
|
+
rescue NameError => e
|
|
99
|
+
raise ::Deprecations.__send__(:name_error, e)
|
|
100
|
+
end
|
|
101
|
+
private(alias_name)
|
|
102
|
+
if alt.is_a?(Symbol)
|
|
94
103
|
begin
|
|
95
|
-
|
|
104
|
+
alt = instance_method(alt)
|
|
96
105
|
rescue NameError => e
|
|
97
106
|
raise ::Deprecations.__send__(:name_error, e)
|
|
98
107
|
end
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
define_method(name) do |*args, **kw_args, &b|
|
|
108
|
-
::Deprecations.call(
|
|
109
|
-
"#{self}.#{::Kernel.__method__}",
|
|
110
|
-
(alt.is_a?(UnboundMethod) ? "#{self}.#{alt.name}" : alt),
|
|
111
|
-
outdated
|
|
112
|
-
)
|
|
113
|
-
__send__(alias_name, *args, **kw_args, &b)
|
|
114
|
-
end
|
|
108
|
+
end
|
|
109
|
+
define_method(name) do |*args, **kw_args, &b|
|
|
110
|
+
::Deprecations.call(
|
|
111
|
+
"#{self}.#{::Kernel.__method__}",
|
|
112
|
+
(alt.is_a?(UnboundMethod) ? "#{self}.#{alt.name}" : alt),
|
|
113
|
+
outdated
|
|
114
|
+
)
|
|
115
|
+
__send__(alias_name, *args, **kw_args, &b)
|
|
115
116
|
end
|
|
116
117
|
end
|
|
118
|
+
end
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
module InstanceMethods
|
|
121
|
+
private
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
def deprecated(name, alt = nil, outdated = nil)
|
|
124
|
+
alias_name = "__deprecated__instance_method__#{name}__"
|
|
125
|
+
return if private_method_defined?(alias_name)
|
|
126
|
+
begin
|
|
127
|
+
alias_method(alias_name, name)
|
|
128
|
+
rescue NameError => e
|
|
129
|
+
::Deprecations.__send__(:name_error, e)
|
|
130
|
+
return singleton_class.__send__(:deprecated, name, alt, outdated)
|
|
131
|
+
end
|
|
132
|
+
private(alias_name)
|
|
133
|
+
if alt.is_a?(Symbol)
|
|
124
134
|
begin
|
|
125
|
-
|
|
135
|
+
alt = instance_method(alt)
|
|
126
136
|
rescue NameError => e
|
|
127
|
-
::Deprecations.__send__(:name_error, e)
|
|
128
|
-
return singleton_class.__send__(:deprecated, name, alt, outdated)
|
|
137
|
+
raise ::Deprecations.__send__(:name_error, e)
|
|
129
138
|
end
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
end
|
|
140
|
+
define_method(name) do |*args, **kw_args, &b|
|
|
141
|
+
pref =
|
|
142
|
+
if defined?(self.class.name)
|
|
143
|
+
self.class.name
|
|
144
|
+
else
|
|
145
|
+
::Kernel.instance_method(:class).bind(self).call
|
|
136
146
|
end
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
pref
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
::Kernel.instance_method(:class).bind(self).call
|
|
144
|
-
end
|
|
145
|
-
::Deprecations.call(
|
|
146
|
-
"#{pref}##{::Kernel.__method__}",
|
|
147
|
-
(alt.is_a?(UnboundMethod) ? "#{pref}##{alt.name}" : alt),
|
|
148
|
-
outdated
|
|
149
|
-
)
|
|
150
|
-
__send__(alias_name, *args, **kw_args, &b)
|
|
151
|
-
end
|
|
147
|
+
::Deprecations.call(
|
|
148
|
+
"#{pref}##{::Kernel.__method__}",
|
|
149
|
+
(alt.is_a?(UnboundMethod) ? "#{pref}##{alt.name}" : alt),
|
|
150
|
+
outdated
|
|
151
|
+
)
|
|
152
|
+
__send__(alias_name, *args, **kw_args, &b)
|
|
152
153
|
end
|
|
154
|
+
end
|
|
153
155
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
end
|
|
156
|
+
def deprecated!(alternative = nil, outdated = nil)
|
|
157
|
+
org = method(:new)
|
|
158
|
+
define_singleton_method(:new) do |*args, **kw_args, &b|
|
|
159
|
+
::Deprecations.call(name, alternative, outdated)
|
|
160
|
+
org.call(*args, **kw_args, &b)
|
|
160
161
|
end
|
|
161
162
|
end
|
|
162
|
-
|
|
163
|
-
Module.extend(ClassMethods)
|
|
164
|
-
Module.include(InstanceMethods)
|
|
165
163
|
end
|
|
166
164
|
|
|
165
|
+
Module.extend(ClassMethods)
|
|
166
|
+
Module.include(InstanceMethods)
|
|
167
|
+
|
|
168
|
+
autoload :VERSION, "#{__dir__}/deprecations/version.rb"
|
|
169
|
+
|
|
170
|
+
private_constant(*(constants - %i[Error VERSION]))
|
|
171
|
+
|
|
167
172
|
self.behavior = :warn
|
|
168
173
|
end
|
metadata
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deprecations
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Blumtritt
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
description:
|
|
13
|
-
|
|
14
|
-
It's easy, small, has no dependencies and no overhead.
|
|
12
|
+
description: 'This gem provides transparent declaration of deprecated methods and
|
|
13
|
+
classes. It''s easy, small, has no dependencies and no overhead. '
|
|
15
14
|
executables: []
|
|
16
15
|
extensions: []
|
|
17
16
|
extra_rdoc_files:
|
|
18
17
|
- README.md
|
|
19
18
|
files:
|
|
20
19
|
- README.md
|
|
20
|
+
- deprecations.gemspec
|
|
21
21
|
- lib/deprecations.rb
|
|
22
22
|
- lib/deprecations/version.rb
|
|
23
|
-
homepage: https://
|
|
24
|
-
licenses:
|
|
23
|
+
homepage: https://codeberg.org/mblumtritt/deprecations
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
- Ruby
|
|
25
27
|
metadata:
|
|
26
|
-
source_code_uri: https://
|
|
27
|
-
bug_tracker_uri: https://
|
|
28
|
+
source_code_uri: https://codeberg.org/mblumtritt/deprecations
|
|
29
|
+
bug_tracker_uri: https://codeberg.org/mblumtritt/deprecations/issues
|
|
28
30
|
rubygems_mfa_required: 'true'
|
|
29
31
|
rdoc_options: []
|
|
30
32
|
require_paths:
|
|
31
33
|
- lib
|
|
32
34
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
35
|
requirements:
|
|
34
|
-
- - "
|
|
36
|
+
- - ">"
|
|
35
37
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: 3.0
|
|
38
|
+
version: '3.0'
|
|
37
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
40
|
requirements:
|
|
39
41
|
- - ">="
|
|
40
42
|
- !ruby/object:Gem::Version
|
|
41
43
|
version: '0'
|
|
42
44
|
requirements: []
|
|
43
|
-
rubygems_version: 3.6.
|
|
45
|
+
rubygems_version: 3.6.9
|
|
44
46
|
specification_version: 4
|
|
45
47
|
summary: Deprecation support for your project.
|
|
46
48
|
test_files: []
|