deprecations 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/deprecations/configuration.rb +2 -2
- data/lib/deprecations/extension.rb +32 -69
- data/lib/deprecations/version.rb +1 -1
- data/lib/deprecations.rb +5 -9
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f3f137ca9a5beb63eb3bdd08488fff97528ca7b
|
4
|
+
data.tar.gz: d7ea7405ba490ee635a0a299acb96af174ac4f10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80b8a7f300eac8799d2b813e0eee5481da2dc06716893a851585c876c21f32c68952f38f30e1233e440decc2249a48163a023b6a3cf74dd9056bbb60058ee25d
|
7
|
+
data.tar.gz: ca23236eda75c3e37649cd464bb9fe22f4944fbd260a318c9980ff6acf63656b1641342f1e0e60baa6fa4856b4f99cfe56f661e9e51348f7797a6e7a036a5b09
|
data/CHANGELOG.md
CHANGED
@@ -10,7 +10,7 @@ module Deprecations
|
|
10
10
|
@@cfg
|
11
11
|
end
|
12
12
|
|
13
|
-
BEHAVIORS = [:warn, :raise, :silence]
|
13
|
+
BEHAVIORS = [:warn, :raise, :silence]
|
14
14
|
|
15
15
|
private
|
16
16
|
|
@@ -25,7 +25,7 @@ module Deprecations
|
|
25
25
|
BEHAVIORS.include?(how) and return @behavior = how
|
26
26
|
::Kernel.raise(
|
27
27
|
::ArgumentError, "invalid parameter `#{how}` - have to be #{BEHAVIORS.map(&:inspect).join(' | ')}"
|
28
|
-
)
|
28
|
+
)
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
1
|
module Deprecations
|
3
2
|
class << self
|
4
3
|
private
|
4
|
+
|
5
5
|
def infect(mod)
|
6
6
|
mod.extend(ClassMethods)
|
7
7
|
mod.send(:include, InstanceMethods)
|
@@ -9,95 +9,58 @@ module Deprecations
|
|
9
9
|
|
10
10
|
module Helper
|
11
11
|
private
|
12
|
-
|
13
|
-
|
14
|
-
private_method_defined?(method_name) and return :private
|
15
|
-
protected_method_defined?(method_name) and return :protected
|
16
|
-
public_method_defined?(method_name) and return :public
|
17
|
-
nil
|
12
|
+
def __method(method_name)
|
13
|
+
instance_method(method_name) rescue nil
|
18
14
|
end
|
19
15
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
def __method_deprecated!(method, alternative, outdated)
|
17
|
+
define_method(method.name) do |*a, &b|
|
18
|
+
decorated = Class === self ? "#{self}." : "#{self.class}#"
|
19
|
+
Deprecations.call(
|
20
|
+
"#{decorated}#{__method__}",
|
21
|
+
alternative.nil? ? nil : "#{decorated}#{alternative.name}",
|
22
|
+
outdated
|
23
|
+
)
|
24
|
+
method.bind(self).call(*a, &b)
|
26
25
|
end
|
27
|
-
name
|
28
26
|
end
|
29
27
|
|
30
|
-
def
|
31
|
-
|
32
|
-
private_method_defined?(alias_name) and raise(ScriptError, "method is already deprecated - #{decorated_name}")
|
33
|
-
alias_method(alias_name, name)
|
34
|
-
private(alias_name)
|
35
|
-
alias_name
|
28
|
+
def __method_not_found!(method_name)
|
29
|
+
raise(NameError, "undefined method `#{method_name}` for class `#{self}`")
|
36
30
|
end
|
31
|
+
|
37
32
|
end
|
38
33
|
|
39
34
|
module ClassMethods
|
40
|
-
include Helper
|
41
35
|
private
|
36
|
+
include Helper
|
42
37
|
|
43
|
-
def deprecated(method_name,
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
->{"#{self.inspect[8..-2]}.#{method_name}"},
|
48
|
-
method_scope,
|
49
|
-
__decorated(alternative_method_name),
|
50
|
-
outdated
|
51
|
-
)
|
52
|
-
ensure
|
53
|
-
$@ and $@.delete_if{ |s| s.index(__FILE__) }
|
54
|
-
end
|
55
|
-
|
56
|
-
def __decorated(name)
|
57
|
-
name or return nil
|
58
|
-
__method_scope(name) and return ->{"#{self.inspect[8..-2]}.#{name}"}
|
59
|
-
Symbol === name and __not_found!(name)
|
60
|
-
name
|
61
|
-
end
|
62
|
-
|
63
|
-
def __not_found!(name)
|
64
|
-
raise(NameError, "undefined method `#{name}` for class `#{self.inspect[8..-2]}`")
|
38
|
+
def deprecated(method_name, alternative = nil, outdated = nil)
|
39
|
+
m = __method(method_name) or __method_not_found!(method_name)
|
40
|
+
a = alternative.nil? ? nil : (__method(alternative) or __method_not_found!(alternative))
|
41
|
+
__method_deprecated!(m, a, outdated)
|
65
42
|
end
|
66
43
|
end
|
67
44
|
|
68
45
|
module InstanceMethods
|
69
|
-
include Helper
|
70
46
|
private
|
47
|
+
include Helper
|
71
48
|
|
72
|
-
def deprecated
|
73
|
-
singleton_class.send(
|
74
|
-
|
75
|
-
|
76
|
-
->{self},
|
77
|
-
:public,
|
78
|
-
alternative ? "#{alternative}" : nil,
|
79
|
-
outdated
|
80
|
-
)
|
81
|
-
end
|
82
|
-
|
83
|
-
def deprecated(method_name, alternative_method_name = nil, outdated = nil)
|
84
|
-
method_scope = __method_scope(method_name) and return __define_deprecated(
|
85
|
-
method_name,
|
86
|
-
->{"#{self}##{method_name}"},
|
87
|
-
method_scope,
|
88
|
-
__decorated(alternative_method_name),
|
89
|
-
outdated
|
90
|
-
)
|
91
|
-
singleton_class.send(:deprecated, method_name, alternative_method_name, outdated)
|
92
|
-
ensure
|
93
|
-
$@ and $@.delete_if{ |s| s.index(__FILE__) }
|
49
|
+
def deprecated(method_name, alternative = nil, outdated = nil)
|
50
|
+
m = __method(method_name) or return singleton_class.send(:deprecated, method_name, alternative, outdated)
|
51
|
+
a = alternative.nil? ? nil : (__method(alternative) or __method_not_found!(alternative))
|
52
|
+
__method_deprecated!(m, a, outdated)
|
94
53
|
end
|
95
54
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
55
|
+
def deprecated!(alternative = nil, outdated = nil)
|
56
|
+
m = method(:new)
|
57
|
+
define_singleton_method(:new) do |*a, &b|
|
58
|
+
Deprecations.call(self, alternative, outdated)
|
59
|
+
m.call(*a, &b)
|
60
|
+
end
|
99
61
|
end
|
100
62
|
end
|
63
|
+
|
101
64
|
end
|
102
65
|
|
103
66
|
infect(Module)
|
data/lib/deprecations/version.rb
CHANGED
data/lib/deprecations.rb
CHANGED
@@ -21,8 +21,8 @@ module Deprecations
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def throw!(subject, alternative)
|
24
|
-
msg = "`#{
|
25
|
-
alternative and msg << " - use #{
|
24
|
+
msg = "`#{subject}` is deprecated"
|
25
|
+
alternative and msg << " - use #{alternative} instead"
|
26
26
|
ex = DeprecationError.new(msg)
|
27
27
|
ex.set_backtrace(caller(3))
|
28
28
|
raise(ex)
|
@@ -30,15 +30,11 @@ module Deprecations
|
|
30
30
|
|
31
31
|
def warn(subject, alternative, outdated)
|
32
32
|
location = ::Kernel.caller_locations(3,1).last and location = "#{location.path}:#{location.lineno}: "
|
33
|
-
msg = "#{location}[DEPRECATION] `#{
|
34
|
-
msg << (
|
35
|
-
alternative
|
33
|
+
msg = "#{location}[DEPRECATION] `#{subject}` is deprecated"
|
34
|
+
msg << (outdated ? " and will be outdated #{outdated}." : '.')
|
35
|
+
alternative and msg << " Please use `#{alternative}` instead."
|
36
36
|
::Kernel.warn(msg)
|
37
37
|
end
|
38
|
-
|
39
|
-
def value(arg)
|
40
|
-
defined?(arg.call) ? arg.call : arg
|
41
|
-
end
|
42
38
|
|
43
39
|
end
|
44
40
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.4
|
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: 2015-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -136,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: 1.3.6
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project: deprecations
|
139
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.4.5
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Deprecation support for your project.
|
143
143
|
test_files: []
|
144
|
-
has_rdoc: false
|