deprecation 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deprecation.rb +1 -0
- data/lib/deprecation/behaviors.rb +19 -2
- data/lib/deprecation/reporting.rb +5 -1
- data/lib/deprecation/rspec.rb +32 -0
- data/lib/deprecation/version.rb +1 -1
- data/spec/deprecation_spec.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f81b6ac3b0ec0e588962e5c9b0314e7a8a3439
|
4
|
+
data.tar.gz: b63ada54354a0804f77c468ade91442b5d82bb72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b8a23cff2ad9efb77fcc4b5ec5d1b120239d2a3163108c97d5ae84241e668f9761253e034ceecc90aeffcb9842e831d477e8ec6b326da1feddfe6cc653086d
|
7
|
+
data.tar.gz: 905c8692fa62dab1eaf683a42b288dab2246a615a258b80bfda4a273f22f97b5bead792f39ceea651ca026fe53fa917425029534f0c130f06ac7ab30970283c8
|
data/lib/deprecation.rb
CHANGED
@@ -39,7 +39,7 @@ module Deprecation
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.deprecations
|
42
|
-
@deprecations ||=
|
42
|
+
@deprecations ||= {}
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.behaviors klass
|
@@ -60,7 +60,24 @@ module Deprecation
|
|
60
60
|
},
|
61
61
|
:raise => Proc.new { |message, callstack| raise message },
|
62
62
|
:silence => Proc.new { |message, callstack| },
|
63
|
-
:test => Proc.new
|
63
|
+
:test => Proc.new do |message, callstack|
|
64
|
+
hash = message.hash + callstack[0..2].join("\n").hash
|
65
|
+
unless self.deprecations[hash]
|
66
|
+
self.deprecations[hash] = { message: message, callstack: callstack, count: 1 }
|
67
|
+
else
|
68
|
+
self.deprecations[hash][:count] += 1
|
69
|
+
end
|
70
|
+
end,
|
71
|
+
:stderr_report => Proc.new do |message, callstack|
|
72
|
+
hash = message.hash + callstack[0..2].join("\n").hash
|
73
|
+
unless self.deprecations[hash]
|
74
|
+
self.deprecations[hash] = { message: message, callstack: callstack, count: 1 }
|
75
|
+
$stderr.puts(message)
|
76
|
+
$stderr.puts callstack.join("\n ") if klass.respond_to? :debug and klass.debug
|
77
|
+
else
|
78
|
+
self.deprecations[hash][:count] += 1
|
79
|
+
end
|
80
|
+
end
|
64
81
|
}
|
65
82
|
end
|
66
83
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Deprecation
|
2
|
+
ACTIVESUPPORT_CONCERN_REGEX = %r{/lib/active_support/concern.rb}
|
3
|
+
IGNORE_REGEX = Regexp.union(ACTIVESUPPORT_CONCERN_REGEX)
|
4
|
+
|
2
5
|
class << self
|
6
|
+
|
3
7
|
attr_accessor :show_full_callstack
|
4
8
|
# Outputs a deprecation warning to the output configured by <tt>ActiveSupport::Deprecation.behavior</tt>
|
5
9
|
#
|
@@ -89,7 +93,7 @@ module Deprecation
|
|
89
93
|
|
90
94
|
def extract_callstack(callstack)
|
91
95
|
deprecation_gem_root = File.expand_path("../..", __FILE__) + "/"
|
92
|
-
offending_line = callstack.find { |line| !line.start_with?(deprecation_gem_root) } || callstack.first
|
96
|
+
offending_line = callstack.find { |line| !line.start_with?(deprecation_gem_root) and line !~ IGNORE_REGEX } || callstack.first
|
93
97
|
if offending_line
|
94
98
|
if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
|
95
99
|
md.captures
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Deprecation
|
2
|
+
class RSpec
|
3
|
+
if defined? ::RSpec and $0 =~ Regexp.union(/rake/, /rspec/)
|
4
|
+
require 'rspec/core'
|
5
|
+
|
6
|
+
Deprecation.default_deprecation_behavior = :stderr_report
|
7
|
+
|
8
|
+
::RSpec.configure do |config|
|
9
|
+
config.after(:suite) do
|
10
|
+
Deprecation::RSpec.report $stderr
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.report io
|
16
|
+
return if Deprecation.deprecations.empty?
|
17
|
+
io.puts "\n\n==== DEPRECATION WARNINGS ===="
|
18
|
+
Deprecation.deprecations.each do |hash, obj|
|
19
|
+
io.puts(obj[:message] + " (#{obj[:count]} times); e.g.: ")
|
20
|
+
io.puts(" " + obj[:callstack][0..4].join("\n ") + "\n\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
io.puts <<-EOF
|
24
|
+
If you need more of the backtrace for any of these deprecations to identify
|
25
|
+
where to make the necessary changes, you can configure
|
26
|
+
`Deprecation.default_deprecation_behavior = :raise`, and it will turn the deprecation
|
27
|
+
warnings into errors, giving you the full backtrace.
|
28
|
+
EOF
|
29
|
+
io.puts "\n\n========\n\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/deprecation/version.rb
CHANGED
data/spec/deprecation_spec.rb
CHANGED
@@ -43,7 +43,7 @@ describe Deprecation do
|
|
43
43
|
|
44
44
|
describe "b" do
|
45
45
|
it "should not be deprecated" do
|
46
|
-
expect { subject.b }.not_to raise_error
|
46
|
+
expect { subject.b }.not_to raise_error
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -96,7 +96,7 @@ describe Deprecation do
|
|
96
96
|
|
97
97
|
it "should provide a useful deprecation trace" do
|
98
98
|
logger.should_receive(:warn).with(/called from old_method/)
|
99
|
-
expect(A.new.old_method).to
|
99
|
+
expect(A.new.old_method).to eq true
|
100
100
|
|
101
101
|
end
|
102
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deprecation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/deprecation/core_ext/module/deprecation.rb
|
86
86
|
- lib/deprecation/method_wrappers.rb
|
87
87
|
- lib/deprecation/reporting.rb
|
88
|
+
- lib/deprecation/rspec.rb
|
88
89
|
- lib/deprecation/version.rb
|
89
90
|
- spec/deprecated_module_spec.rb
|
90
91
|
- spec/deprecation_spec.rb
|
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
112
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.4.5
|
113
114
|
signing_key:
|
114
115
|
specification_version: 4
|
115
116
|
summary: Stand-alone deprecation library borrowed from ActiveSupport::Deprecation
|