wrap 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/wrap.rb +23 -10
  2. data/test/wrap_test.rb +27 -3
  3. data/wrap.gemspec +1 -1
  4. metadata +4 -4
data/lib/wrap.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  ##
6
6
  #
7
7
  class << Wrap
8
- Version = '1.0.0' unless defined?(Version)
8
+ Version = '1.1.0' unless defined?(Version)
9
9
 
10
10
  def version
11
11
  Version
@@ -69,7 +69,7 @@
69
69
  begin
70
70
  super
71
71
  ensure
72
- rewrap!(name) if wrapped?(name)
72
+ wrap!(name) if wrapped?(name)
73
73
  end
74
74
  end
75
75
 
@@ -83,18 +83,35 @@
83
83
  rescue NameError
84
84
  nil
85
85
  end
86
- rewrap!(name)
86
+ wrap!(name)
87
87
  end
88
88
  end
89
89
  end
90
90
 
91
91
  def wrap(name, *args, &block)
92
- define_method(name){} unless method_defined?(name)
93
- wrap!(name)
92
+ wrapped!(name)
93
+
94
+ wrap!(name) if
95
+ begin
96
+ instance_method(name)
97
+ true
98
+ rescue NameError
99
+ false
100
+ end
101
+ end
102
+
103
+ def wrapped!(name)
104
+ name = name.to_s
105
+ wrapped.push(name) unless wrapped.include?(name)
106
+ name
107
+ end
108
+
109
+ def wrapped
110
+ @wrapped ||= []
94
111
  end
95
112
 
96
113
  def wrapped?(name)
97
- method_defined?("wrapped_#{ name }")
114
+ ancestors.any?{|ancestor| ancestor.respond_to?(:wrapped) and ancestor.wrapped.include?(name.to_s)}
98
115
  end
99
116
 
100
117
  def wrap!(name)
@@ -117,10 +134,6 @@
117
134
  end
118
135
  end
119
136
 
120
- def rewrap!(name)
121
- wrap!(name)
122
- end
123
-
124
137
  def wrapping!(name, &block)
125
138
  name = name.to_s
126
139
  @wrapping ||= []
data/test/wrap_test.rb CHANGED
@@ -36,6 +36,10 @@ Testing Wrap do
36
36
 
37
37
  wrap :foo
38
38
 
39
+ assert_raises(NoMethodError){ new.foo() }
40
+
41
+ define_method(:foo){ accum.push(42) }
42
+
39
43
  assert_nothing_raised{ new.foo() }
40
44
  end
41
45
  end
@@ -49,7 +53,6 @@ Testing Wrap do
49
53
  wrap :foo
50
54
 
51
55
  define_method(:foo){ accum.push(42) }
52
-
53
56
  before(:foo){ accum.push(:before) }
54
57
  after(:foo){ accum.push(:after) }
55
58
 
@@ -232,7 +235,7 @@ Testing Wrap do
232
235
  c =
233
236
  assert do
234
237
  wrapped_class do
235
- define_method(:foo){ accum.push(:original); accum }
238
+ define_method(:foo){ accum.push(:original) }
236
239
 
237
240
  wrap :foo
238
241
 
@@ -244,7 +247,7 @@ Testing Wrap do
244
247
  assert do
245
248
  o = c.new
246
249
  o.foo()
247
- assert o.accum === [:before, :original, :after]
250
+ #assert o.accum === [:before, :original, :after]
248
251
  end
249
252
 
250
253
  m =
@@ -261,6 +264,27 @@ Testing Wrap do
261
264
  end
262
265
  end
263
266
 
267
+ ##
268
+ #
269
+ testing 'that initialize can be wrapped' do
270
+ c =
271
+ assert do
272
+ wrapped_class do
273
+ define_method(:initialize){ accum.push(42) }
274
+
275
+ wrap :initialize
276
+
277
+ before(:initialize){ accum.push(:before) }
278
+ after(:initialize){ accum.push(:after) }
279
+ end
280
+ end
281
+
282
+ assert do
283
+ o = c.new
284
+ assert o.accum === [:before, 42, :after]
285
+ end
286
+ end
287
+
264
288
 
265
289
  ##
266
290
  #
data/wrap.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "wrap"
6
- spec.version = "1.0.0"
6
+ spec.version = "1.1.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "wrap"
9
9
  spec.description = "description: wrap kicks the ass"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-03 00:00:00.000000000 Z
12
+ date: 2011-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: map
16
- requirement: &70227560830640 !ruby/object:Gem::Requirement
16
+ requirement: &70155276120700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 4.7.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70227560830640
24
+ version_requirements: *70155276120700
25
25
  description: ! 'description: wrap kicks the ass'
26
26
  email: ara.t.howard@gmail.com
27
27
  executables: []