deprecator 0.0.3 → 0.0.4
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.
- data/README.md +18 -0
- data/examples/example.rb +10 -1
- data/lib/deprecator.rb +12 -4
- data/lib/deprecator/core_ext.rb +4 -1
- data/lib/deprecator/strategy.rb +5 -7
- data/lib/deprecator/version.rb +1 -1
- data/spec/deprecator_spec.rb +13 -1
- data/spec/strategy/warning_spec.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -49,6 +49,10 @@ class SomeClass
|
|
49
49
|
|
50
50
|
deprecated_method :method4, "%{method} is no longer here, use some other method!"
|
51
51
|
deprecated_method [:method5, :method6], "%{method} is no longer here, use some other method!"
|
52
|
+
|
53
|
+
def method7
|
54
|
+
raise_deprecated # raises regardless of strategy
|
55
|
+
end
|
52
56
|
end
|
53
57
|
|
54
58
|
obj = SomeClass.new # outputs to stderr: [DEPRECATED] deprecated class SomeClass instantiated at /Users/vasfed/work/deprecator/examples/example.rb:26:in `new'
|
@@ -57,6 +61,12 @@ obj.method2 # [DEPRECATED] this is deprecated when true is true
|
|
57
61
|
obj.method3 # [DEPRECATED] method method3 is deprecated. Called from /Users/vasfed/work/deprecator/examples/example.rb:28:in `<top (required)>'
|
58
62
|
obj.method4 # [DEPRECATED] method4 is no longer here, use some other method!
|
59
63
|
obj.method6 # [DEPRECATED] method6 is no longer here, use some other method!
|
64
|
+
begin
|
65
|
+
obj.method7
|
66
|
+
rescue Deprecator::Deprecated
|
67
|
+
puts "error raised" # guess what? :)
|
68
|
+
end
|
69
|
+
|
60
70
|
|
61
71
|
```
|
62
72
|
|
@@ -96,6 +106,14 @@ SomeClass.new
|
|
96
106
|
|
97
107
|
```
|
98
108
|
|
109
|
+
Note that for BasicObject helpers are not loaded by default, you should do smth like
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
class BasicObject
|
113
|
+
include ::Deprecator::ClassClassMethods
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
99
117
|
## Contributing
|
100
118
|
|
101
119
|
1. Fork it
|
data/examples/example.rb
CHANGED
@@ -21,6 +21,10 @@ class SomeClass
|
|
21
21
|
|
22
22
|
deprecated_method :method4, "%{method} is no longer here, use some other method!"
|
23
23
|
deprecated_method [:method5, :method6], "%{method} is no longer here, use some other method!"
|
24
|
+
|
25
|
+
def method7
|
26
|
+
raise_deprecated # raises regardless of strategy
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
obj = SomeClass.new # outputs to stderr: [DEPRECATED] deprecated class SomeClass instantiated at /Users/vasfed/work/deprecator/examples/example.rb:26:in `new'
|
@@ -28,4 +32,9 @@ obj.method1 # [DEPRECATED] method1 is deprecated!
|
|
28
32
|
obj.method2 # [DEPRECATED] this is deprecated when true is true
|
29
33
|
obj.method3 # [DEPRECATED] method method3 is deprecated. Called from /Users/vasfed/work/deprecator/examples/example.rb:28:in `<top (required)>'
|
30
34
|
obj.method4 # [DEPRECATED] method4 is no longer here, use some other method!
|
31
|
-
obj.method6 # [DEPRECATED] method6 is no longer here, use some other method!
|
35
|
+
obj.method6 # [DEPRECATED] method6 is no longer here, use some other method!
|
36
|
+
begin
|
37
|
+
obj.method7
|
38
|
+
rescue Deprecator::Deprecated
|
39
|
+
puts "error raised" # guess what? :)
|
40
|
+
end
|
data/lib/deprecator.rb
CHANGED
@@ -109,19 +109,27 @@ module Deprecator
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def self.strategy= s
|
112
|
-
case s
|
113
|
-
when
|
112
|
+
@@strategy = case s
|
113
|
+
when nil then DefaultStrategy.new
|
114
|
+
when Class then s.new
|
114
115
|
when Symbol then
|
115
116
|
capitalized = s.capitalize
|
116
117
|
if Strategy.const_defined?(capitalized)
|
117
|
-
|
118
|
+
Strategy.const_get(capitalized).new
|
118
119
|
else
|
119
120
|
raise UnknownStrategy, s
|
120
121
|
end
|
121
122
|
else
|
122
|
-
|
123
|
+
s
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
127
|
+
def self.with_strategy new_strategy
|
128
|
+
old_strategy = strategy
|
129
|
+
self.strategy = new_strategy
|
130
|
+
yield
|
131
|
+
self.strategy = old_strategy
|
132
|
+
end
|
125
133
|
end
|
126
134
|
|
127
135
|
|
data/lib/deprecator/core_ext.rb
CHANGED
@@ -10,7 +10,10 @@ end
|
|
10
10
|
|
11
11
|
module Kernel
|
12
12
|
def deprecated reason=nil, *args
|
13
|
-
Deprecator.strategy.
|
13
|
+
::Deprecator.strategy.plain_deprecated(reason, caller_line, args)
|
14
|
+
end
|
15
|
+
def raise_deprecated reason=nil, *args
|
16
|
+
raise ::Deprecator::Deprecated, reason, *args
|
14
17
|
end
|
15
18
|
alias DEPRECATED deprecated
|
16
19
|
|
data/lib/deprecator/strategy.rb
CHANGED
@@ -4,7 +4,6 @@ module Deprecator
|
|
4
4
|
class Base
|
5
5
|
#on class/module definition/extenting with deprecater or deprecate statement
|
6
6
|
def class_found cls, where=nil, reason=nil, args=nil
|
7
|
-
this = self
|
8
7
|
cls.send(:define_method, :initialize){|*args|
|
9
8
|
::Deprecator.strategy.object_found(cls, self, reason, caller_line, where)
|
10
9
|
}
|
@@ -34,21 +33,20 @@ module Deprecator
|
|
34
33
|
end
|
35
34
|
# on method definition
|
36
35
|
def method_found cls,name, reason, where=nil
|
37
|
-
this = self
|
38
36
|
unless cls.method_defined?(name) # also we may place stubs there for existing methods in other strategies
|
39
37
|
cls.send :define_method, name, ->(*args){
|
40
|
-
|
38
|
+
::Deprecator.strategy.method_called cls,name,reason,caller_line,where
|
41
39
|
}
|
42
40
|
else
|
43
41
|
method = cls.instance_method(name)
|
44
42
|
cls.send :define_method, name, ->(*args){
|
45
|
-
|
43
|
+
::Deprecator.strategy.method_called cls,name,reason,caller_line,where
|
46
44
|
method.bind(self).call(*args)
|
47
45
|
}
|
48
46
|
end
|
49
47
|
end
|
50
48
|
def method_called cls,name,reason=nil,where,defined_at; end
|
51
|
-
def
|
49
|
+
def plain_deprecated reason=nil, where=caller_line, args=nil; end
|
52
50
|
def fixme! msg, where, args; end
|
53
51
|
def todo! msg, where, args; end
|
54
52
|
def not_implemented msg, where, args
|
@@ -72,7 +70,7 @@ module Deprecator
|
|
72
70
|
msg reason.gsub('%{method}', name.to_s), where
|
73
71
|
end
|
74
72
|
|
75
|
-
def
|
73
|
+
def plain_deprecated reason=nil, where=caller_line, args=nil
|
76
74
|
where =~ /in `(.+)'$/
|
77
75
|
method_name = $1 || '<unknown>'
|
78
76
|
reason ||= "%{method} is deprecated!"
|
@@ -93,7 +91,7 @@ module Deprecator
|
|
93
91
|
raise DeprecatedMethodCalled, (reason || "deprecated").gsub('%{method}', name.to_s)
|
94
92
|
end
|
95
93
|
|
96
|
-
def
|
94
|
+
def plain_deprecated reason=nil, where=caller_line, args=nil
|
97
95
|
where =~ /in `(.+)'$/
|
98
96
|
method_name = $1 || '<unknown>'
|
99
97
|
reason ||= "%{method} is deprecated!"
|
data/lib/deprecator/version.rb
CHANGED
data/spec/deprecator_spec.rb
CHANGED
@@ -49,10 +49,14 @@ describe Deprecator do
|
|
49
49
|
subject.strategy = :base
|
50
50
|
}
|
51
51
|
it "simple" do
|
52
|
-
subject.strategy.should_receive(:
|
52
|
+
subject.strategy.should_receive(:plain_deprecated).with("reason", duck_type(:to_s), [])
|
53
53
|
deprecated "reason"
|
54
54
|
end
|
55
55
|
|
56
|
+
it "raise_deprecated" do
|
57
|
+
expect{ raise_deprecated }.to raise_error(Deprecator::Deprecated)
|
58
|
+
end
|
59
|
+
|
56
60
|
it "marking in class" do
|
57
61
|
cls = Class.new{
|
58
62
|
deprecated_method "reason"
|
@@ -120,5 +124,13 @@ describe Deprecator do
|
|
120
124
|
expect{ subject.strategy = :no_such_strategy }.to raise_error(Deprecator::UnknownStrategy)
|
121
125
|
end
|
122
126
|
end
|
127
|
+
|
128
|
+
it "with" do
|
129
|
+
expect{
|
130
|
+
subject.with_strategy(Object) do
|
131
|
+
deprecated
|
132
|
+
end
|
133
|
+
}.to raise_error(NoMethodError, /plain_deprecated/)
|
134
|
+
end
|
123
135
|
end
|
124
136
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deprecator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: is_a
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash:
|
121
|
+
hash: -1744994072693929959
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
124
|
rubygems_version: 1.8.24
|