deprecator 0.0.4 → 0.1.0

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/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
  require 'deprecator'
32
32
 
33
33
  class SomeClass
34
- deprecated
34
+ deprecated_class
35
35
 
36
36
  def method1
37
37
  deprecated
@@ -77,7 +77,7 @@ changing strategies:
77
77
  Deprecator.strategy = :raise # included: warning(default), raise, raiseHard
78
78
 
79
79
  class SomeClass
80
- deprecated "some reason"
80
+ deprecated_class "some reason"
81
81
  def initialize
82
82
  puts "SomeClass#initialize called"
83
83
  end
@@ -3,7 +3,7 @@
3
3
  require 'deprecator'
4
4
 
5
5
  class SomeClass
6
- deprecated
6
+ deprecated_class
7
7
 
8
8
  def method1
9
9
  deprecated
@@ -5,7 +5,7 @@ require 'deprecator'
5
5
  Deprecator.strategy = :raise # included: warning(default), raise, raiseHard
6
6
 
7
7
  class SomeClass
8
- deprecated "some reason"
8
+ deprecated_class "some reason"
9
9
  def initialize
10
10
  puts "SomeClass#initialize called"
11
11
  end
@@ -51,7 +51,7 @@ module Deprecator
51
51
 
52
52
 
53
53
  module ClassClassMethods
54
- def deprecated reason=nil, *args
54
+ def deprecated_class reason=nil, *args
55
55
  ::Deprecator.strategy.class_found(self, caller_line, reason, args)
56
56
  end
57
57
 
@@ -62,21 +62,19 @@ module Deprecator
62
62
  @method_added_stack.push(m)
63
63
  end
64
64
 
65
- @skip_next_method_added_addition = true
65
+ Deprecator._skip_next_method_added_addition!
66
66
  define_singleton_method(:method_added, ->(name){
67
67
  return if name == :method_added
68
68
  super(name)
69
69
  old = @method_added_stack.pop
70
70
  if old
71
- @skip_next_method_added_addition = true
71
+ Deprecator._skip_next_method_added_addition!
72
72
  define_singleton_method(:method_added, old)
73
- remove_instance_variable :@skip_next_method_added_addition
74
73
  else
75
74
  class <<self; remove_method(:method_added); end
76
75
  end
77
76
  blk.call(name)
78
77
  })
79
- remove_instance_variable :@skip_next_method_added_addition
80
78
  end
81
79
 
82
80
  def deprecated_method name=nil, reason=nil, &blk
@@ -130,6 +128,27 @@ module Deprecator
130
128
  yield
131
129
  self.strategy = old_strategy
132
130
  end
131
+
132
+ #@private
133
+ def self._skip_next_initialize_addition!
134
+ @_skip_next_initialize_addition = true
135
+ end
136
+ #@private
137
+ def self._skip_next_initialize_addition?
138
+ return false if !@_skip_next_initialize_addition
139
+ remove_instance_variable :@_skip_next_initialize_addition
140
+ return true
141
+ end
142
+ #@private
143
+ def self._skip_next_method_added_addition!
144
+ @_skip_next_method_added_addition = true
145
+ end
146
+ #@private
147
+ def self._skip_next_method_added_addition?
148
+ return false if !@_skip_next_method_added_addition
149
+ remove_instance_variable :@_skip_next_method_added_addition
150
+ return true
151
+ end
133
152
  end
134
153
 
135
154
 
@@ -10,19 +10,18 @@ module Deprecator
10
10
 
11
11
  cls.send(:define_singleton_method, :method_added, ->(name){
12
12
  super(name)
13
- if name == :initialize && !@skip_next_initialize_addition
13
+ if name == :initialize && !Deprecator._skip_next_initialize_addition?
14
14
  meth = instance_method(name)
15
- @skip_next_initialize_addition = true
15
+ Deprecator::_skip_next_initialize_addition!
16
16
  define_method(name){|*args|
17
17
  ::Deprecator.strategy.object_found(cls, self, reason, caller_line, where)
18
18
  meth.bind(self).call(*args)
19
19
  }
20
- remove_instance_variable :@skip_next_initialize_addition
21
20
  end
22
21
  })
23
22
  cls.send(:define_singleton_method, :singleton_method_added, ->(name){
24
23
  #guard for self?
25
- if name == :method_added && !@skip_next_method_added_addition
24
+ if name == :method_added && !Deprecator._skip_next_method_added_addition?
26
25
  warn "[WARNING] when you replace method_added for deprecated class - you can no longer autotrack its object creation, use deprecation of initialize method."
27
26
  end
28
27
  })
@@ -1,3 +1,3 @@
1
1
  module Deprecator
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -25,7 +25,15 @@ describe Deprecator do
25
25
  end
26
26
  it "via call to deprecated" do
27
27
  subject.strategy.should_receive(:class_found).with(kind_of(Class), duck_type(:to_s), "abc", [])
28
- Class.new{ deprecated "abc" }
28
+ Class.new{ deprecated_class "abc" }
29
+ end
30
+ it "class methods" do
31
+ subject.strategy.should_receive(:class_found).with(kind_of(Class), duck_type(:to_s), "aa", []).once
32
+ subject.strategy.should_receive(:plain_deprecated).with("bb", duck_type(:to_s), [])
33
+ (Class.new{
34
+ deprecated_class "aa"
35
+ def self.cls_method; deprecated "bb"; end
36
+ }).cls_method
29
37
  end
30
38
  end
31
39
 
@@ -40,7 +48,7 @@ describe Deprecator do
40
48
  end
41
49
  it "via call to deprecated" do
42
50
  subject.strategy.should_receive(:class_found).with(kind_of(Module), duck_type(:to_s), "abc", [])
43
- Module.new{ deprecated "abc" }
51
+ Module.new{ deprecated_class "abc" }
44
52
  end
45
53
  end
46
54
 
@@ -86,14 +94,14 @@ describe Deprecator do
86
94
  end
87
95
 
88
96
  it "with reason passed" do
89
- cls = Class.new{ deprecated "reason" }
97
+ cls = Class.new{ deprecated_class "reason" }
90
98
  subject.strategy.should_receive(:object_found).with(cls, kind_of(cls), "reason", /#{Regexp.escape __FILE__}:#{__LINE__+1}/, /#{Regexp.escape __FILE__}:#{__LINE__-1}/)
91
99
  cls.new
92
100
  end
93
101
 
94
102
  it "and guards for initialize method" do
95
103
  cls = Class.new{
96
- deprecated "reason"
104
+ deprecated_class "reason"
97
105
  # def self.method_added(name); puts "method added #{name}"; end
98
106
  def initialize
99
107
  self.class.initialize_called
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: -1744994072693929959
121
+ hash: -593577026750073995
122
122
  requirements: []
123
123
  rubyforge_project:
124
124
  rubygems_version: 1.8.24