deprecation 0.0.1 → 0.0.2
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/lib/deprecation.rb +25 -16
- data/lib/deprecation/behaviors.rb +0 -2
- data/lib/deprecation/core_ext/module/deprecation.rb +5 -0
- data/lib/deprecation/method_wrappers.rb +3 -5
- data/lib/deprecation/reporting.rb +10 -10
- data/lib/deprecation/version.rb +1 -1
- data/spec/deprecated_module_spec.rb +45 -0
- data/spec/deprecation_spec.rb +4 -4
- data/spec/spec_helper.rb +0 -7
- metadata +5 -2
data/lib/deprecation.rb
CHANGED
@@ -2,33 +2,42 @@ require 'deprecation/behaviors'
|
|
2
2
|
require 'deprecation/reporting'
|
3
3
|
require 'deprecation/method_wrappers'
|
4
4
|
require 'active_support/concern'
|
5
|
+
require 'deprecation/core_ext/module/deprecation'
|
5
6
|
|
6
7
|
module Deprecation
|
7
8
|
extend ActiveSupport::Concern
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def deprecation_horizon= horizon
|
11
|
+
@deprecation_horizon = horizon
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def deprecation_horizon
|
15
|
+
@deprecation_horizon
|
16
|
+
end
|
15
17
|
|
16
|
-
|
18
|
+
def silenced
|
19
|
+
@silenced
|
20
|
+
end
|
21
|
+
|
22
|
+
def silenced= bool
|
23
|
+
@silenced = bool
|
24
|
+
end
|
25
|
+
|
26
|
+
def debug
|
27
|
+
@debug
|
28
|
+
end
|
29
|
+
|
30
|
+
def debug= bool
|
31
|
+
@debug = bool
|
32
|
+
end
|
33
|
+
|
34
|
+
included do
|
35
|
+
class << self
|
17
36
|
end
|
18
37
|
|
19
38
|
# By default, warnings are not silenced and debugging is off.
|
20
39
|
self.silenced = false
|
21
40
|
self.debug = false
|
22
41
|
end
|
23
|
-
|
24
|
-
module ClassMethods
|
25
|
-
def deprecate *method_names
|
26
|
-
# Declare that a method has been deprecated.
|
27
|
-
# deprecate :foo
|
28
|
-
# deprecate :bar => 'message'
|
29
|
-
# deprecate :foo, :bar, :baz => 'warning!', :qux => 'gone!'
|
30
|
-
deprecate_methods(self, *method_names)
|
31
|
-
end
|
32
|
-
end
|
33
42
|
end
|
34
43
|
|
@@ -2,7 +2,6 @@ require "active_support/notifications"
|
|
2
2
|
require "active_support/concern"
|
3
3
|
|
4
4
|
module Deprecation
|
5
|
-
module ClassMethods
|
6
5
|
|
7
6
|
# Returns the current behavior or if one isn't set, defaults to +:stderr+
|
8
7
|
def deprecation_behavior
|
@@ -32,7 +31,6 @@ module Deprecation
|
|
32
31
|
def deprecation_behavior=(deprecation_behavior)
|
33
32
|
@deprecation_behavior = Array(deprecation_behavior).map { |b| Deprecation.behaviors(self)[b] || b }
|
34
33
|
end
|
35
|
-
end
|
36
34
|
|
37
35
|
def self.deprecations
|
38
36
|
@deprecations ||= []
|
@@ -2,9 +2,8 @@ require 'active_support/core_ext/module/aliasing'
|
|
2
2
|
require 'active_support/core_ext/array/extract_options'
|
3
3
|
|
4
4
|
module Deprecation
|
5
|
-
module ClassMethods
|
6
5
|
# Declare that a method has been deprecated.
|
7
|
-
def deprecate_methods(target_module, *method_names)
|
6
|
+
def self.deprecate_methods(target_module, *method_names)
|
8
7
|
options = method_names.extract_options!
|
9
8
|
method_names += options.keys
|
10
9
|
|
@@ -12,8 +11,8 @@ module Deprecation
|
|
12
11
|
target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
|
13
12
|
target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
|
14
13
|
def #{target}_with_deprecation#{punctuation}(*args, &block)
|
15
|
-
|
16
|
-
|
14
|
+
Deprecation.warn(#{target_module.to_s},
|
15
|
+
Deprecation.deprecated_method_warning(#{target_module.to_s},
|
17
16
|
:#{method_name},
|
18
17
|
#{options[method_name].inspect}),
|
19
18
|
caller
|
@@ -24,5 +23,4 @@ module Deprecation
|
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
27
|
-
end
|
28
26
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Deprecation
|
2
|
-
|
2
|
+
class << self
|
3
3
|
# Outputs a deprecation warning to the output configured by <tt>ActiveSupport::Deprecation.behavior</tt>
|
4
4
|
#
|
5
5
|
# Deprecation.warn("something broke!")
|
6
6
|
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
|
7
|
-
def warn(message = nil, callstack = caller)
|
8
|
-
return if silenced
|
7
|
+
def warn(context, message = nil, callstack = caller)
|
8
|
+
return if context.silenced
|
9
9
|
deprecation_message(callstack, message).tap do |m|
|
10
|
-
deprecation_behavior.each { |b| b.call(m, callstack) }
|
10
|
+
context.deprecation_behavior.each { |b| b.call(m, callstack) }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -19,19 +19,19 @@ module Deprecation
|
|
19
19
|
@silenced = old_silenced
|
20
20
|
end
|
21
21
|
|
22
|
-
def collect
|
23
|
-
old_behavior =
|
22
|
+
def collect(context)
|
23
|
+
old_behavior = context.deprecation_behavior
|
24
24
|
deprecations = []
|
25
|
-
|
25
|
+
context.deprecation_behavior = Proc.new do |message, callstack|
|
26
26
|
deprecations << message
|
27
27
|
end
|
28
28
|
result = yield
|
29
29
|
[result, deprecations]
|
30
30
|
ensure
|
31
|
-
|
31
|
+
context.deprecation_behavior = old_behavior
|
32
32
|
end
|
33
33
|
|
34
|
-
def deprecated_method_warning(method_name, options = nil)
|
34
|
+
def deprecated_method_warning(context, method_name, options = nil)
|
35
35
|
|
36
36
|
options ||= {}
|
37
37
|
|
@@ -40,7 +40,7 @@ module Deprecation
|
|
40
40
|
options = {}
|
41
41
|
end
|
42
42
|
|
43
|
-
warning = "#{method_name} is deprecated and will be removed from #{options[:deprecation_horizon] || deprecation_horizon}"
|
43
|
+
warning = "#{method_name} is deprecated and will be removed from #{options[:deprecation_horizon] || context.deprecation_horizon}"
|
44
44
|
case message
|
45
45
|
when Symbol then "#{warning} (use #{message} instead)"
|
46
46
|
when String then "#{warning} (#{message})"
|
data/lib/deprecation/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "deprecated module methods" do
|
4
|
+
module DeprecatedModule
|
5
|
+
extend Deprecation
|
6
|
+
|
7
|
+
self.deprecation_behavior = :raise
|
8
|
+
|
9
|
+
self.deprecation_horizon = 'release 0.1'
|
10
|
+
def a
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
deprecation_deprecate :a
|
15
|
+
end
|
16
|
+
|
17
|
+
module DeprecatedModuleLater
|
18
|
+
extend Deprecation
|
19
|
+
|
20
|
+
self.deprecation_behavior = :raise
|
21
|
+
|
22
|
+
self.deprecation_horizon = 'release 0.2'
|
23
|
+
def b
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
deprecation_deprecate :b
|
28
|
+
end
|
29
|
+
class DeprecationModuleTest
|
30
|
+
include DeprecatedModule
|
31
|
+
include DeprecatedModuleLater
|
32
|
+
end
|
33
|
+
subject { DeprecationModuleTest.new}
|
34
|
+
|
35
|
+
describe "a" do
|
36
|
+
it "should be deprecated" do
|
37
|
+
expect { subject.a }.to raise_error /a is deprecated/
|
38
|
+
end
|
39
|
+
end
|
40
|
+
describe "b" do
|
41
|
+
it "should be deprecated in release 0.2" do
|
42
|
+
expect { subject.b }.to raise_error /b is deprecated and will be removed from release 0.2/
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/deprecation_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Deprecation do
|
4
4
|
class DeprecationTest
|
5
|
-
|
5
|
+
extend Deprecation
|
6
6
|
self.deprecation_behavior = :raise
|
7
7
|
|
8
8
|
self.deprecation_horizon = 'release 0.1'
|
@@ -12,7 +12,7 @@ describe Deprecation do
|
|
12
12
|
1
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
deprecation_deprecate :a
|
16
16
|
|
17
17
|
def b
|
18
18
|
|
@@ -26,12 +26,12 @@ describe Deprecation do
|
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
deprecation_deprecate :c, :d
|
30
30
|
|
31
31
|
def e
|
32
32
|
|
33
33
|
end
|
34
|
-
|
34
|
+
deprecation_deprecate :e => { :deprecation_horizon => 'asdf 1.4' }
|
35
35
|
end
|
36
36
|
subject { DeprecationTest.new}
|
37
37
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deprecation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -87,9 +87,11 @@ files:
|
|
87
87
|
- deprecation.gemspec
|
88
88
|
- lib/deprecation.rb
|
89
89
|
- lib/deprecation/behaviors.rb
|
90
|
+
- lib/deprecation/core_ext/module/deprecation.rb
|
90
91
|
- lib/deprecation/method_wrappers.rb
|
91
92
|
- lib/deprecation/reporting.rb
|
92
93
|
- lib/deprecation/version.rb
|
94
|
+
- spec/deprecated_module_spec.rb
|
93
95
|
- spec/deprecation_spec.rb
|
94
96
|
- spec/spec_helper.rb
|
95
97
|
homepage: http://github.com/cbeer/deprecation
|
@@ -106,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
108
|
version: '0'
|
107
109
|
segments:
|
108
110
|
- 0
|
109
|
-
hash:
|
111
|
+
hash: -342229614951663189
|
110
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
113
|
none: false
|
112
114
|
requirements:
|
@@ -120,5 +122,6 @@ signing_key:
|
|
120
122
|
specification_version: 3
|
121
123
|
summary: Stand-alone deprecation library borrowed from ActiveSupport::Deprecation
|
122
124
|
test_files:
|
125
|
+
- spec/deprecated_module_spec.rb
|
123
126
|
- spec/deprecation_spec.rb
|
124
127
|
- spec/spec_helper.rb
|