deprecated 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +27 -41
  2. data/lib/deprecated.rb +110 -110
  3. data/test/test_deprecated.rb +78 -76
  4. metadata +41 -40
data/Rakefile CHANGED
@@ -2,18 +2,14 @@
2
2
  # Please see the COPYING file in the source distribution for copyright information.
3
3
  #
4
4
 
5
- begin
6
- require 'rubygems'
7
- gem 'test-unit'
8
- rescue LoadError
9
- end
10
-
11
- $:.unshift 'lib'
5
+ require 'rubygems'
6
+ require 'rubygems/package_task'
12
7
  require 'rake/testtask'
13
- require 'rake/packagetask'
14
- require 'rake/gempackagetask'
15
8
  require 'rdoc/task'
9
+
10
+ $:.unshift 'lib'
16
11
  require 'deprecated'
12
+ $:.shift
17
13
 
18
14
  task :default => [ :dist ]
19
15
 
@@ -22,9 +18,9 @@ task :default => [ :dist ]
22
18
  #
23
19
 
24
20
  Rake::TestTask.new do |t|
25
- t.libs << 'lib'
26
- t.test_files = FileList['test/test*.rb']
27
- t.verbose = true
21
+ t.libs << 'lib'
22
+ t.test_files = FileList['test/test*.rb']
23
+ t.verbose = true
28
24
  end
29
25
 
30
26
  #
@@ -35,21 +31,16 @@ task :dist => [:test, :repackage, :gem, :rdoc]
35
31
  task :distclean => [:clobber_package, :clobber_rdoc]
36
32
  task :clean => [:distclean]
37
33
 
38
- task :to_blog => [:clobber_rdoc, :rdoc] do
39
- sh "rm -r $git/blog/content/docs/deprecated && mv rdoc $git/blog/content/docs/deprecated"
40
- end
41
-
42
-
43
34
  #
44
35
  # Documentation
45
36
  #
46
37
 
47
38
  RDoc::Task.new do |rd|
48
- rd.rdoc_dir = "rdoc"
49
- rd.main = "README"
50
- rd.rdoc_files.include("README")
51
- rd.rdoc_files.include("./lib/**/*.rb")
52
- rd.options = %w(-a)
39
+ rd.rdoc_dir = "rdoc"
40
+ rd.main = "README"
41
+ rd.rdoc_files.include("README")
42
+ rd.rdoc_files.include("./lib/**/*.rb")
43
+ rd.options = %w(-a)
53
44
  end
54
45
 
55
46
  #
@@ -57,25 +48,20 @@ end
57
48
  #
58
49
 
59
50
  spec = Gem::Specification.new do |s|
60
- s.name = "deprecated"
61
- s.version = Deprecated::VERSION
62
- s.author = "Erik Hollensbe"
63
- s.email = "erik@hollensbe.org"
64
- s.summary = "An easy way to handle deprecating and conditionally running deprecated code"
65
- s.has_rdoc = true
66
- s.files = Dir['Rakefile'] + Dir['lib/deprecated.rb'] + Dir['test/test_deprecated.rb']
67
- s.test_file = "test/test_deprecated.rb"
68
- s.rubyforge_project = 'deprecated'
69
- end
70
-
71
- Rake::GemPackageTask.new(spec) do |s|
51
+ s.name = "deprecated"
52
+ s.version = Deprecated::VERSION
53
+ s.author = "Erik Hollensbe"
54
+ s.email = "erik@hollensbe.org"
55
+ s.summary = "An easy way to handle deprecating and conditionally running deprecated code"
56
+ s.has_rdoc = true
57
+ s.files = Dir['Rakefile'] + Dir['lib/deprecated.rb'] + Dir['test/test_deprecated.rb']
58
+ s.test_file = "test/test_deprecated.rb"
59
+ s.rubyforge_project = 'deprecated'
60
+ s.license = "MIT"
61
+ s.add_development_dependency "test-unit", ">= 0"
72
62
  end
73
63
 
74
- Rake::PackageTask.new(spec.name, spec.version) do |p|
75
- p.need_tar_gz = true
76
- p.need_zip = true
77
- p.package_files.include("./setup.rb")
78
- p.package_files.include("./Rakefile")
79
- p.package_files.include("./lib/**/*.rb")
80
- p.package_files.include("./test/**/*")
64
+ Gem::PackageTask.new(spec) do |p|
65
+ p.need_tar_gz = true
66
+ p.need_zip = true
81
67
  end
@@ -70,134 +70,134 @@ class DeprecatedError < StandardError; end
70
70
  # Deprecated::Module#deprecated_set_action for more information.
71
71
  #
72
72
  module Deprecated
73
- VERSION = "3.0.0"
73
+ VERSION = "3.0.1"
74
74
 
75
- def __deprecated_run_action__(sym, replacement)
76
- if self.class.instance_eval { @__deprecated_run_action__ }
77
- self.class.instance_eval { @__deprecated_run_action__ }.call(self.class, sym, replacement)
78
- else
79
- Deprecated.run_action(self.class, sym, replacement)
80
- end
75
+ def __deprecated_run_action__(sym, replacement)
76
+ if self.class.instance_eval { @__deprecated_run_action__ }
77
+ self.class.instance_eval { @__deprecated_run_action__ }.call(self.class, sym, replacement)
78
+ else
79
+ Deprecated.run_action(self.class, sym, replacement)
81
80
  end
81
+ end
82
82
 
83
- def self.build_message(klass, sym, replacement)
84
- message = "#{klass}##{sym} is deprecated."
85
-
86
- if replacement
87
- message += " Please use #{replacement}."
88
- end
83
+ def self.build_message(klass, sym, replacement)
84
+ message = "#{klass}##{sym} is deprecated."
89
85
 
90
- return message
86
+ if replacement
87
+ message += " Please use #{replacement}."
91
88
  end
92
89
 
93
- #
94
- # set_action takes 3 "canned" arguments or an arbitrary block. If you
95
- # provide the block, any canned argument is ignored.
96
- #
97
- # The canned arguments are:
98
- #
99
- # :warn:: display a warning
100
- # :raise:: raise a DeprecatedError (a kind of StandardError) with the warning.
101
- # :fail:: fail. die. kaput. it's over.
102
- #
103
- # Procs take three arguments:
104
- #
105
- # - The class of the method
106
- # - The method name itself, a symbol
107
- # - A replacement string which may be nil
108
- #
109
- def self.set_action(type=nil, &block)
110
- @action = if block
111
- block
112
- else
113
- case type
114
- when :warn
115
- proc { |*args| warn build_message(*args) }
116
- when :fail
117
- proc { |*args| fail build_message(*args) }
118
- when :raise
119
- proc { |*args| raise DeprecatedError, build_message(*args) }
120
- else
121
- raise ArgumentError, "you must provide a symbol or a block to set_action()."
122
- end
123
- end
124
- end
90
+ return message
91
+ end
125
92
 
126
- #
127
- # Is called when an action needs to be run. Proably not in your best
128
- # interest to run this directly.
129
- #
130
- def self.run_action(klass, sym, replacement)
131
- raise "run_action has no associated hook" unless @action
132
- @action.call(klass, sym, replacement)
133
- end
93
+ #
94
+ # set_action takes 3 "canned" arguments or an arbitrary block. If you
95
+ # provide the block, any canned argument is ignored.
96
+ #
97
+ # The canned arguments are:
98
+ #
99
+ # :warn:: display a warning
100
+ # :raise:: raise a DeprecatedError (a kind of StandardError) with the warning.
101
+ # :fail:: fail. die. kaput. it's over.
102
+ #
103
+ # Procs take three arguments:
104
+ #
105
+ # - The class of the method
106
+ # - The method name itself, a symbol
107
+ # - A replacement string which may be nil
108
+ #
109
+ def self.set_action(type=nil, &block)
110
+ @action = if block
111
+ block
112
+ else
113
+ case type
114
+ when :warn
115
+ proc { |*args| warn build_message(*args) }
116
+ when :fail
117
+ proc { |*args| fail build_message(*args) }
118
+ when :raise
119
+ proc { |*args| raise DeprecatedError, build_message(*args) }
120
+ else
121
+ raise ArgumentError, "you must provide a symbol or a block to set_action()."
122
+ end
123
+ end
124
+ end
134
125
 
135
- #
136
- # Returns the current action; this may be block or Proc.
137
- #
138
- def self.action
139
- @action
140
- end
126
+ #
127
+ # Is called when an action needs to be run. Proably not in your best
128
+ # interest to run this directly.
129
+ #
130
+ def self.run_action(klass, sym, replacement)
131
+ raise "run_action has no associated hook" unless @action
132
+ @action.call(klass, sym, replacement)
133
+ end
134
+
135
+ #
136
+ # Returns the current action; this may be block or Proc.
137
+ #
138
+ def self.action
139
+ @action
140
+ end
141
141
  end
142
142
 
143
143
  module Deprecated
144
- module Module
144
+ module Module
145
145
 
146
- #
147
- # deprecated takes up to three arguments:
148
- #
149
- # - A symbol which is the name of the method you wish to deprecate
150
- # (required)
151
- # - A string or symbol which is the replacement method. If you provide
152
- # this, your users will be instructed to use that method instead.
153
- # - A symbol of :public, :private, or :protected which determines the
154
- # new scope of the method. If you do not provide one, it will be
155
- # searched for in the various collections, and scope will be chosen
156
- # that way.
157
- #
158
- def deprecated(sym, replacement=nil, scope=nil)
159
- unless sym.kind_of?(Symbol)
160
- raise ArgumentError, "deprecated() requires symbols for its first argument."
161
- end
146
+ #
147
+ # deprecated takes up to three arguments:
148
+ #
149
+ # - A symbol which is the name of the method you wish to deprecate
150
+ # (required)
151
+ # - A string or symbol which is the replacement method. If you provide
152
+ # this, your users will be instructed to use that method instead.
153
+ # - A symbol of :public, :private, or :protected which determines the
154
+ # new scope of the method. If you do not provide one, it will be
155
+ # searched for in the various collections, and scope will be chosen
156
+ # that way.
157
+ #
158
+ def deprecated(sym, replacement=nil, scope=nil)
159
+ unless sym.kind_of?(Symbol)
160
+ raise ArgumentError, "deprecated() requires symbols for its first argument."
161
+ end
162
162
 
163
- meth = instance_method(sym)
164
- unless scope
165
- pub = public_instance_methods
166
- pro = protected_instance_methods
167
- pri = private_instance_methods
168
- if pub.include?(sym) or pub.include?(sym.to_s)
169
- scope = :public
170
- elsif pro.include?(sym) or pro.include?(sym.to_s)
171
- scope = :protected
172
- elsif pri.include?(sym) or pri.include?(sym.to_s)
173
- scope = :private
174
- end
175
- end
163
+ meth = instance_method(sym)
164
+ unless scope
165
+ pub = public_instance_methods
166
+ pro = protected_instance_methods
167
+ pri = private_instance_methods
168
+ if pub.include?(sym) or pub.include?(sym.to_s)
169
+ scope = :public
170
+ elsif pro.include?(sym) or pro.include?(sym.to_s)
171
+ scope = :protected
172
+ elsif pri.include?(sym) or pri.include?(sym.to_s)
173
+ scope = :private
174
+ end
175
+ end
176
176
 
177
- define_method(sym) do |*args|
178
- dep_meth = method(sym).unbind
179
- __deprecated_run_action__(sym, replacement)
180
- retval = meth.bind(self).call(*args)
181
- dep_meth.bind(self)
182
- return retval
183
- end
177
+ define_method(sym) do |*args|
178
+ dep_meth = method(sym).unbind
179
+ __deprecated_run_action__(sym, replacement)
180
+ retval = meth.bind(self).call(*args)
181
+ dep_meth.bind(self)
182
+ return retval
183
+ end
184
184
 
185
- method(scope).call(sym) if scope
186
- return scope
187
- end
185
+ method(scope).call(sym) if scope
186
+ return scope
187
+ end
188
188
 
189
- #
190
- # Deprecated.set_action for class scope. See Deprecated.set_action.
191
- #
192
- def deprecated_set_action(&block)
193
- raise "You must provide a block" unless block
194
- @__deprecated_run_action__ = block
195
- end
189
+ #
190
+ # Deprecated.set_action for class scope. See Deprecated.set_action.
191
+ #
192
+ def deprecated_set_action(&block)
193
+ raise "You must provide a block" unless block
194
+ @__deprecated_run_action__ = block
196
195
  end
196
+ end
197
197
 
198
- def self.included(base)
199
- base.extend(Module)
200
- end
198
+ def self.included(base)
199
+ base.extend(Module)
200
+ end
201
201
  end
202
202
 
203
203
  Deprecated.set_action(:warn)
@@ -3,111 +3,113 @@
3
3
  require 'rubygems'
4
4
  gem 'test-unit'
5
5
  require 'test/unit'
6
- require 'lib/deprecated.rb'
6
+ $:.unshift 'lib'
7
+ require 'deprecated.rb'
8
+ $:.shift
7
9
 
8
10
  # this class is used to test the deprecate functionality
9
11
  class DummyClass
10
- include Deprecated
12
+ include Deprecated
11
13
 
12
- def monkey
13
- return true
14
- end
14
+ def monkey
15
+ return true
16
+ end
15
17
 
16
- def monkey_bars
17
- return true
18
- end
18
+ def monkey_bars
19
+ return true
20
+ end
19
21
 
20
- deprecated :monkey
21
- deprecated :monkey_bars, "FooClass#fart"
22
+ deprecated :monkey
23
+ deprecated :monkey_bars, "FooClass#fart"
22
24
 
23
- protected
25
+ protected
24
26
 
25
- def my_protected
26
- return true
27
- end
27
+ def my_protected
28
+ return true
29
+ end
28
30
 
29
- deprecated :my_protected
31
+ deprecated :my_protected
30
32
 
31
- private
33
+ private
32
34
 
33
- def my_private
34
- return true
35
- end
35
+ def my_private
36
+ return true
37
+ end
36
38
 
37
- deprecated :my_private
39
+ deprecated :my_private
38
40
  end
39
41
 
40
42
  class DummyClass2
41
- include Deprecated
43
+ include Deprecated
42
44
 
43
- deprecated_set_action do |klass, sym, replacement|
44
- raise DeprecatedError, "foo!"
45
- end
45
+ deprecated_set_action do |klass, sym, replacement|
46
+ raise DeprecatedError, "foo!"
47
+ end
46
48
 
47
- def monkey
48
- return true
49
- end
49
+ def monkey
50
+ return true
51
+ end
50
52
 
51
- deprecated :monkey
53
+ deprecated :monkey
52
54
  end
53
55
 
54
56
  # we want exceptions for testing here.
55
57
  Deprecated.set_action(:raise)
56
58
 
57
59
  class DeprecateTest < Test::Unit::TestCase
58
- def test_set_action
59
- assert_raises(DeprecatedError) { DummyClass.new.monkey }
60
-
61
- Deprecated.set_action { |klass, sym| raise DeprecatedError.new("#{klass}##{sym} is deprecated.") }
62
- assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do
63
- DummyClass.new.monkey
64
- end
60
+ def test_set_action
61
+ assert_raises(DeprecatedError) { DummyClass.new.monkey }
65
62
 
66
- Deprecated.set_action(:raise)
67
-
68
- assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do
69
- DummyClass.new.monkey
70
- end
71
-
72
- # set to warn and make sure our return values are getting through.
73
- Deprecated.set_action(:warn)
74
- assert(DummyClass.new.monkey)
75
-
76
- Kernel.module_eval {
77
- def self.fail
78
- raise "failed"
79
- end
80
- }
81
-
82
- Deprecated.set_action(:fail)
83
-
84
- assert_raises("failed") { DummyClass.new.monkey }
63
+ Deprecated.set_action { |klass, sym| raise DeprecatedError.new("#{klass}##{sym} is deprecated.") }
64
+ assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do
65
+ DummyClass.new.monkey
85
66
  end
86
67
 
87
- def test_scope
88
- assert(
89
- DummyClass.public_instance_methods.include?(:monkey) ||
90
- DummyClass.public_instance_methods.include?("monkey")
91
- )
92
- assert(
93
- DummyClass.protected_instance_methods.include?(:my_protected) ||
94
- DummyClass.protected_instance_methods.include?("my_protected")
95
- )
96
- assert(
97
- DummyClass.private_instance_methods.include?(:my_private) ||
98
- DummyClass.private_instance_methods.include?("my_private")
99
- )
100
- end
68
+ Deprecated.set_action(:raise)
101
69
 
102
- def test_scoped_actions
103
- assert_raises(DeprecatedError.new("foo!")) { DummyClass2.new.monkey }
70
+ assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do
71
+ DummyClass.new.monkey
104
72
  end
105
73
 
106
- def test_replacement
107
- Deprecated.set_action(:raise)
108
-
109
- assert_raises(DeprecatedError.new("DummyClass#monkey_bars is deprecated. Please use FooClass#fart.")) do
110
- DummyClass.new.monkey_bars
111
- end
74
+ # set to warn and make sure our return values are getting through.
75
+ Deprecated.set_action(:warn)
76
+ assert(DummyClass.new.monkey)
77
+
78
+ Kernel.module_eval {
79
+ def self.fail
80
+ raise "failed"
81
+ end
82
+ }
83
+
84
+ Deprecated.set_action(:fail)
85
+
86
+ assert_raises("failed") { DummyClass.new.monkey }
87
+ end
88
+
89
+ def test_scope
90
+ assert(
91
+ DummyClass.public_instance_methods.include?(:monkey) ||
92
+ DummyClass.public_instance_methods.include?("monkey")
93
+ )
94
+ assert(
95
+ DummyClass.protected_instance_methods.include?(:my_protected) ||
96
+ DummyClass.protected_instance_methods.include?("my_protected")
97
+ )
98
+ assert(
99
+ DummyClass.private_instance_methods.include?(:my_private) ||
100
+ DummyClass.private_instance_methods.include?("my_private")
101
+ )
102
+ end
103
+
104
+ def test_scoped_actions
105
+ assert_raises(DeprecatedError.new("foo!")) { DummyClass2.new.monkey }
106
+ end
107
+
108
+ def test_replacement
109
+ Deprecated.set_action(:raise)
110
+
111
+ assert_raises(DeprecatedError.new("DummyClass#monkey_bars is deprecated. Please use FooClass#fart.")) do
112
+ DummyClass.new.monkey_bars
112
113
  end
114
+ end
113
115
  end
metadata CHANGED
@@ -1,64 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: deprecated
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 3
7
- - 0
8
- - 0
9
- version: 3.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Erik Hollensbe
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-05-05 00:00:00 -04:00
18
- default_executable:
19
- dependencies: []
20
-
12
+ date: 2012-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-unit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
21
30
  description:
22
31
  email: erik@hollensbe.org
23
32
  executables: []
24
-
25
33
  extensions: []
26
-
27
34
  extra_rdoc_files: []
28
-
29
- files:
35
+ files:
30
36
  - Rakefile
31
37
  - lib/deprecated.rb
32
38
  - test/test_deprecated.rb
33
- has_rdoc: true
34
39
  homepage:
35
- licenses: []
36
-
40
+ licenses:
41
+ - MIT
37
42
  post_install_message:
38
43
  rdoc_options: []
39
-
40
- require_paths:
44
+ require_paths:
41
45
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- segments:
47
- - 0
48
- version: "0"
49
- required_rubygems_version: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
56
58
  requirements: []
57
-
58
59
  rubyforge_project: deprecated
59
- rubygems_version: 1.3.6
60
+ rubygems_version: 1.8.24
60
61
  signing_key:
61
62
  specification_version: 3
62
63
  summary: An easy way to handle deprecating and conditionally running deprecated code
63
- test_files:
64
+ test_files:
64
65
  - test/test_deprecated.rb