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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd629dd649dd88a3ef88453c700740bc88044205
4
- data.tar.gz: 53cbaedda1b182264cb857ee7dac26eebc5cea8b
3
+ metadata.gz: a2f81b6ac3b0ec0e588962e5c9b0314e7a8a3439
4
+ data.tar.gz: b63ada54354a0804f77c468ade91442b5d82bb72
5
5
  SHA512:
6
- metadata.gz: 8cd66fa50d5f4d2e480baad348faf3c95c7cff4b44dd718122d1daa2112871cb882ad288b10e8877376ff1d9f3b95bedfdf0ae09c0721d5c8a929d5f1f994ee2
7
- data.tar.gz: 9011487732bdd87dcc96ac67e30b0c91f5a92968da2adc16abd7cf3d82601a8e0ccbdfd907ab08ad235d95c9e3e2eeebb4f926d30a218af1ea00a8333518f1b4
6
+ metadata.gz: a6b8a23cff2ad9efb77fcc4b5ec5d1b120239d2a3163108c97d5ae84241e668f9761253e034ceecc90aeffcb9842e831d477e8ec6b326da1feddfe6cc653086d
7
+ data.tar.gz: 905c8692fa62dab1eaf683a42b288dab2246a615a258b80bfda4a273f22f97b5bead792f39ceea651ca026fe53fa917425029534f0c130f06ac7ab30970283c8
@@ -3,6 +3,7 @@ require 'deprecation/reporting'
3
3
  require 'deprecation/method_wrappers'
4
4
  require 'active_support/concern'
5
5
  require 'deprecation/core_ext/module/deprecation'
6
+ require 'deprecation/rspec'
6
7
 
7
8
  module Deprecation
8
9
  extend ActiveSupport::Concern
@@ -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 { |message, callstack| self.deprecations << message }
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
@@ -1,3 +1,3 @@
1
1
  module Deprecation
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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 /b is deprecated/
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 be_true
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.1.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: 2014-02-03 00:00:00.000000000 Z
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.2.0
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