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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 976d65184fd1442180e364ecd885aabf9202877f1bb7d11c1315eed9fe30b5ee
4
- data.tar.gz: bf4ad1bc538b49878a6268321883d1d89a3cc3fe0627ef8c2d37200972c22ad2
3
+ metadata.gz: 9973f05a62830c682760b9becfce855fa3e25d2bfdb40a0516846b5e3e27297f
4
+ data.tar.gz: 77b6ca73354da20235e652895d30513dc4f3ab47dd3bd73658eeb250d2cac52c
5
5
  SHA512:
6
- metadata.gz: 29383bc82baad099e0597f6efb0c4a0e2d4bb7f87e2235c19e1ebd58e0611c287aa7b1f478c1e75fc942f43bd2078cfb09f80f90df72ab4d184012e2dee8a51d
7
- data.tar.gz: 0636b27fc0c83e46df73364b669b6c59f0c2e844e424807a990ee45d8bf1957b93db289d744d63013b099317f8f23618aa92b979c468a200712608956bd220a7
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
- ```bash
18
- $ bundle
17
+ ```shell
18
+ $ bundle add deprecations
19
19
  ```
20
20
 
21
21
  To install the gem globally use:
22
22
 
23
- ```bash
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 = proc do |subject, _alternative, _outdated|
83
- SuperLogger.warning "deprecated: #{subject}"
84
- end
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) do
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
- begin
18
- @behavior = behavior
19
- yield
20
- ensure
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 `call`"
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
- msg = "`#{subject}` is deprecated"
47
- msg << " - use #{alternative} instead" if alternative
48
- ex = Error.new(msg)
49
- ex.set_backtrace(caller(3))
50
- raise(ex)
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
- msg = "`#{subject}` is deprecated"
57
- msg << (outdated ? " and will be outdated #{outdated}." : '.')
58
- msg << " Please use `#{alternative}` instead." if alternative
59
- ::Kernel.warn(msg, uplevel: 3)
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
- class << self
5
- private
6
-
7
- def infect(mod)
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
- def __method(method_name)
16
- begin
17
- instance_method(method_name)
18
- rescue StandardError
19
- nil
20
- end
21
- end
9
+ module ClassMethods
10
+ private
22
11
 
23
- def __method_deprecated!(method, alternative, outdated)
24
- defining_context = self
25
- undef_method(method.name)
26
- define_method(method.name) do |*a, &b|
27
- decorated = Class === self ? "#{self}." : "#{defining_context}#"
28
- alternative = "#{decorated}#{alternative.name}" if UnboundMethod ===
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
- Deprecations.call(
31
- "#{decorated}#{::Kernel.__method__}",
32
- alternative,
33
- outdated
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
- module ClassMethods
53
- private
54
-
55
- include Helper
33
+ module InstanceMethods
34
+ private
56
35
 
57
- def deprecated(method_name, alternative = nil, outdated = nil)
58
- __method_deprecated!(
59
- __method_checked(method_name),
60
- __method_alternative(alternative),
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
- module InstanceMethods
67
- private
68
-
69
- include Helper
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deprecations
4
- VERSION = '2.2.2'
4
+ VERSION = '2.5.0'
5
5
  end
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.2.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: 2022-07-30 00:00:00.000000000 Z
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.0.0
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.3.7
48
+ rubygems_version: 3.5.1
48
49
  signing_key:
49
50
  specification_version: 4
50
51
  summary: Deprecation support for your project.