deprecation 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +6 -0
- data/Gemfile +1 -4
- data/LICENSE +20 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/deprecation.gemspec +4 -3
- data/lib/deprecation.rb +16 -0
- data/lib/deprecation/behaviors.rb +3 -9
- data/lib/deprecation/reporting.rb +22 -5
- data/lib/deprecation/version.rb +1 -1
- data/spec/deprecation_spec.rb +26 -0
- metadata +23 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cd629dd649dd88a3ef88453c700740bc88044205
|
4
|
+
data.tar.gz: 53cbaedda1b182264cb857ee7dac26eebc5cea8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cd66fa50d5f4d2e480baad348faf3c95c7cff4b44dd718122d1daa2112871cb882ad288b10e8877376ff1d9f3b95bedfdf0ae09c0721d5c8a929d5f1f994ee2
|
7
|
+
data.tar.gz: 9011487732bdd87dcc96ac67e30b0c91f5a92968da2adc16abd7cf3d82601a8e0ccbdfd907ab08ad235d95c9e3e2eeebb4f926d30a218af1ea00a8333518f1b4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Chris Beer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
Deprecation
|
2
|
+
------------
|
3
|
+
[![Build Status](https://travis-ci.org/cbeer/deprecation.png?branch=master)](https://travis-ci.org/cbeer/deprecation)
|
4
|
+
|
5
|
+
Provide deprecation warnings for code
|
6
|
+
|
7
|
+
## Add warnings
|
8
|
+
```ruby
|
9
|
+
class DeprecatedModule
|
10
|
+
extend Deprecation
|
11
|
+
self.deprecation_horizon = 'my_gem version 3.0.0'
|
12
|
+
|
13
|
+
def asdf
|
14
|
+
|
15
|
+
end
|
16
|
+
deprecation_deprecate :asdf
|
17
|
+
|
18
|
+
def custom_deprecation *args
|
19
|
+
Deprecation.warn(DeprecatedModule, "don't do that!") if args.length < 15
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
DeprecatedModule.new.asdf
|
25
|
+
DEPRECATION WARNING: asdf is deprecated and will be removed from my_gem version 3.0.0. (called from irb_binding at (irb):18)
|
26
|
+
=> nil
|
27
|
+
|
28
|
+
```
|
29
|
+
|
30
|
+
## Silence warnings
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
|
34
|
+
def silence_asdf_warning
|
35
|
+
Deprecation.silence(DeprecationModule) do
|
36
|
+
asdf
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Reporting
|
42
|
+
```ruby
|
43
|
+
Deprecation.default_deprecation_behavior = :stderr # the default
|
44
|
+
|
45
|
+
Deprecation.default_deprecation_behavior = :log # put deprecation warnings into the Rails / ActiveSupport log
|
46
|
+
|
47
|
+
DeprecationModule.debug = true # put the full callstack in the logged message
|
48
|
+
|
49
|
+
Deprecation.default_deprecation_behavior = :notify # use ActiveSupport::Notifications to log the message
|
50
|
+
|
51
|
+
Deprecation.default_deprecation_behavior = :raise # Raise an exception when using deprecated behavior
|
52
|
+
|
53
|
+
Deprecation.default_deprecation_behavior = :silence # ignore all deprecations
|
54
|
+
|
55
|
+
```
|
data/Rakefile
CHANGED
data/deprecation.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.summary = %q{Stand-alone deprecation library borrowed from ActiveSupport::Deprecation}
|
11
11
|
s.description = %q{Stand-alone deprecation library borrowed from ActiveSupport::Deprecation}
|
12
12
|
s.homepage = "http://github.com/cbeer/deprecation"
|
13
|
+
s.license = "MIT"
|
13
14
|
|
14
15
|
s.files = `git ls-files`.split("\n")
|
15
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -18,8 +19,8 @@ Gem::Specification.new do |s|
|
|
18
19
|
|
19
20
|
s.add_dependency "activesupport"
|
20
21
|
|
21
|
-
s.add_development_dependency
|
22
|
-
s.add_development_dependency
|
23
|
-
s.add_development_dependency
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec", ">= 2.14"
|
24
|
+
s.add_development_dependency "bundler", ">= 1.0.14"
|
24
25
|
end
|
25
26
|
|
data/lib/deprecation.rb
CHANGED
@@ -19,6 +19,8 @@ module Deprecation
|
|
19
19
|
@silenced
|
20
20
|
end
|
21
21
|
|
22
|
+
alias_method :silenced?, :silenced
|
23
|
+
|
22
24
|
def silenced= bool
|
23
25
|
@silenced = bool
|
24
26
|
end
|
@@ -26,11 +28,25 @@ module Deprecation
|
|
26
28
|
def debug
|
27
29
|
@debug
|
28
30
|
end
|
31
|
+
alias_method :debug?, :debug
|
29
32
|
|
30
33
|
def debug= bool
|
31
34
|
@debug = bool
|
32
35
|
end
|
33
36
|
|
37
|
+
def self.logger
|
38
|
+
@logger ||= if defined?(Rails) && Rails.logger
|
39
|
+
Rails.logger
|
40
|
+
else
|
41
|
+
require 'active_support/logger'
|
42
|
+
ActiveSupport::Logger.new($stderr)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.logger= value
|
47
|
+
@logger = value
|
48
|
+
end
|
49
|
+
|
34
50
|
included do
|
35
51
|
class << self
|
36
52
|
end
|
@@ -47,18 +47,12 @@ module Deprecation
|
|
47
47
|
{
|
48
48
|
:stderr => Proc.new { |message, callstack|
|
49
49
|
$stderr.puts(message)
|
50
|
-
$stderr.puts callstack.join("\n ") if klass.debug
|
50
|
+
$stderr.puts callstack.join("\n ") if klass.respond_to? :debug and klass.debug
|
51
51
|
},
|
52
52
|
:log => Proc.new { |message, callstack|
|
53
|
-
logger =
|
54
|
-
if defined?(Rails) && Rails.logger
|
55
|
-
Rails.logger
|
56
|
-
else
|
57
|
-
require 'active_support/logger'
|
58
|
-
ActiveSupport::Logger.new($stderr)
|
59
|
-
end
|
53
|
+
logger = Deprecation.logger
|
60
54
|
logger.warn message
|
61
|
-
logger.debug callstack.join("\n ") if klass.debug
|
55
|
+
logger.debug callstack.join("\n ") if klass.respond_to? :debug and klass.debug
|
62
56
|
},
|
63
57
|
:notify => Proc.new { |message, callstack|
|
64
58
|
ActiveSupport::Notifications.instrument("deprecation.#{klass.to_s}",
|
@@ -5,19 +5,36 @@ module Deprecation
|
|
5
5
|
#
|
6
6
|
# Deprecation.warn("something broke!")
|
7
7
|
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
|
8
|
-
def warn(context, message = nil, callstack =
|
9
|
-
return if context.silenced
|
8
|
+
def warn(context, message = nil, callstack = nil)
|
9
|
+
return if context.respond_to? :silenced? and context.silenced?
|
10
|
+
|
11
|
+
if callstack.nil?
|
12
|
+
callstack = caller
|
13
|
+
callstack.shift
|
14
|
+
end
|
15
|
+
|
10
16
|
deprecation_message(callstack, message).tap do |m|
|
11
|
-
context.
|
17
|
+
deprecation_behavior(context).each { |b| b.call(m, callstack) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def deprecation_behavior context
|
22
|
+
if context.respond_to? :deprecation_behavior
|
23
|
+
context.deprecation_behavior
|
24
|
+
else
|
25
|
+
[Deprecation.behaviors(self)[Deprecation.default_deprecation_behavior]]
|
12
26
|
end
|
13
27
|
end
|
14
28
|
|
15
29
|
# Silence deprecation warnings within the block.
|
16
30
|
def silence context
|
17
|
-
|
31
|
+
if context.respond_to? :silenced=
|
32
|
+
old_silenced, context.silenced = context.silenced, true
|
33
|
+
end
|
34
|
+
|
18
35
|
yield
|
19
36
|
ensure
|
20
|
-
context.silenced = old_silenced
|
37
|
+
context.silenced = old_silenced if context.respond_to? :silenced=
|
21
38
|
end
|
22
39
|
|
23
40
|
def collect(context)
|
data/lib/deprecation/version.rb
CHANGED
data/spec/deprecation_spec.rb
CHANGED
@@ -74,4 +74,30 @@ describe Deprecation do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
77
|
+
|
78
|
+
describe "warn" do
|
79
|
+
class A
|
80
|
+
def some_deprecated_method
|
81
|
+
Deprecation.warn(A, "some explicit deprecation warning")
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
def old_method
|
86
|
+
some_deprecated_method
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:logger) { double() }
|
91
|
+
|
92
|
+
before(:each) do
|
93
|
+
Deprecation.stub logger: logger
|
94
|
+
Deprecation.stub default_deprecation_behavior: :log
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should provide a useful deprecation trace" do
|
98
|
+
logger.should_receive(:warn).with(/called from old_method/)
|
99
|
+
expect(A.new.old_method).to be_true
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
77
103
|
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deprecation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Chris Beer
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
47
|
+
version: '2.14'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
54
|
+
version: '2.14'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: bundler
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 1.0.14
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 1.0.14
|
78
69
|
description: Stand-alone deprecation library borrowed from ActiveSupport::Deprecation
|
@@ -82,7 +73,11 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
85
78
|
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
86
81
|
- Rakefile
|
87
82
|
- deprecation.gemspec
|
88
83
|
- lib/deprecation.rb
|
@@ -95,31 +90,28 @@ files:
|
|
95
90
|
- spec/deprecation_spec.rb
|
96
91
|
- spec/spec_helper.rb
|
97
92
|
homepage: http://github.com/cbeer/deprecation
|
98
|
-
licenses:
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
99
96
|
post_install_message:
|
100
97
|
rdoc_options: []
|
101
98
|
require_paths:
|
102
99
|
- lib
|
103
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
101
|
requirements:
|
106
|
-
- -
|
102
|
+
- - ">="
|
107
103
|
- !ruby/object:Gem::Version
|
108
104
|
version: '0'
|
109
|
-
segments:
|
110
|
-
- 0
|
111
|
-
hash: -2491741378934253569
|
112
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
106
|
requirements:
|
115
|
-
- -
|
107
|
+
- - ">="
|
116
108
|
- !ruby/object:Gem::Version
|
117
109
|
version: '0'
|
118
110
|
requirements: []
|
119
111
|
rubyforge_project:
|
120
|
-
rubygems_version:
|
112
|
+
rubygems_version: 2.2.0
|
121
113
|
signing_key:
|
122
|
-
specification_version:
|
114
|
+
specification_version: 4
|
123
115
|
summary: Stand-alone deprecation library borrowed from ActiveSupport::Deprecation
|
124
116
|
test_files:
|
125
117
|
- spec/deprecated_module_spec.rb
|