extlib 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of extlib might be problematic. Click here for more details.
- data/History.txt +18 -0
- data/LICENSE +27 -0
- data/Rakefile +1 -1
- data/lib/extlib/class.rb +1 -1
- data/lib/extlib/hook.rb +25 -6
- data/lib/extlib/lazy_array.rb +117 -47
- data/lib/extlib/module.rb +5 -1
- data/lib/extlib/version.rb +1 -1
- data/spec/class_spec.rb +18 -2
- data/spec/hook_spec.rb +28 -0
- data/spec/lazy_array_spec.rb +106 -42
- data/spec/module_spec.rb +4 -4
- data/spec/pooling_spec.rb +1 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
=== 0.9.10 / 2009-01-19
|
2
|
+
|
3
|
+
* 1 major enhancement:
|
4
|
+
|
5
|
+
* Ruby 1.9.1 compatibility
|
6
|
+
|
7
|
+
* 1 minor enhancement:
|
8
|
+
|
9
|
+
* Updated LazyArray#eql? and LazyArray#== to compare without lazy
|
10
|
+
loading if possible.
|
11
|
+
|
12
|
+
3 bug fixes:
|
13
|
+
|
14
|
+
* Fix for inheritance and hooks
|
15
|
+
* Fix for Class inheritable accessor to use #try_dup
|
16
|
+
* Fix for LazyArray to be more explicit in delegating to Array,
|
17
|
+
to lessen conflicts in subclasses
|
18
|
+
|
1
19
|
=== 0.9.9 / 2008-12-07
|
2
20
|
|
3
21
|
* 1 major enhancement:
|
data/LICENSE
CHANGED
@@ -18,3 +18,30 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
---
|
23
|
+
---
|
24
|
+
|
25
|
+
Some portions of blank.rb and mash.rb are verbatim copies of software
|
26
|
+
licensed under the MIT license. That license is included below:
|
27
|
+
|
28
|
+
Copyright (c) 2005-2008 David Heinemeier Hansson
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
"Software"), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
44
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
45
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
46
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
47
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -75,7 +75,7 @@ namespace :extlib do
|
|
75
75
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
76
76
|
t.spec_opts << '--format' << 'specdoc' << '--colour'
|
77
77
|
t.spec_opts << '--loadby' << 'random'
|
78
|
-
t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb')
|
78
|
+
t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb').map { |f| f.to_s }
|
79
79
|
|
80
80
|
begin
|
81
81
|
gem 'rcov'
|
data/lib/extlib/class.rb
CHANGED
@@ -118,7 +118,7 @@ class Class
|
|
118
118
|
return @#{ivar} if self.object_id == #{self.object_id} || defined?(@#{ivar})
|
119
119
|
ivar = superclass.#{ivar}
|
120
120
|
return nil if ivar.nil? && !#{self}.instance_variable_defined?("@#{ivar}")
|
121
|
-
@#{ivar} = ivar
|
121
|
+
@#{ivar} = ivar.try_dup
|
122
122
|
end
|
123
123
|
RUBY
|
124
124
|
unless instance_reader == false
|
data/lib/extlib/hook.rb
CHANGED
@@ -249,7 +249,7 @@ module Extlib
|
|
249
249
|
|
250
250
|
source = %{class << self\n#{source}\nend} if scope == :class
|
251
251
|
|
252
|
-
hooks[target_method][:in].class_eval(source, __FILE__, __LINE__)
|
252
|
+
hooks[target_method][:in].class_eval(source, __FILE__, __LINE__ - 12)
|
253
253
|
end
|
254
254
|
|
255
255
|
# Returns ruby code that will invoke the hook. It checks the arity of the hook method
|
@@ -283,7 +283,7 @@ module Extlib
|
|
283
283
|
end
|
284
284
|
EOD
|
285
285
|
|
286
|
-
if scope == :instance && !instance_methods(false).include?(target_method.to_s)
|
286
|
+
if scope == :instance && !instance_methods(false).map { |m| m.to_s }.include?(target_method.to_s)
|
287
287
|
send(:alias_method, renamed_target, target_method)
|
288
288
|
|
289
289
|
proxy_module = Module.new
|
@@ -315,14 +315,33 @@ module Extlib
|
|
315
315
|
raise ArgumentError, 'You need to pass :class or :instance as scope'
|
316
316
|
end
|
317
317
|
|
318
|
-
|
319
|
-
|
320
|
-
|
318
|
+
if registered_as_hook?(target_method, scope)
|
319
|
+
hooks = hooks_with_scope(scope)
|
320
|
+
|
321
|
+
#if this hook is previously declared in a sibling or cousin we must move the :in class
|
322
|
+
#to the common ancestor to get both hooks to run.
|
323
|
+
if !(hooks[target_method][:in] <=> self)
|
324
|
+
hooks[target_method][:in].class_eval(
|
325
|
+
%{def #{hook_method_name(target_method, 'execute_before', 'hook_stack')}(*args);super;end\n} +
|
326
|
+
%{def #{hook_method_name(target_method, 'execute_after', 'hook_stack')}(*args);super;end},
|
327
|
+
__FILE__,__LINE__ - 2
|
328
|
+
)
|
329
|
+
while !(hooks[target_method][:in] <=> self) do
|
330
|
+
hooks[target_method][:in] = hooks[target_method][:in].superclass
|
331
|
+
end
|
332
|
+
define_hook_stack_execution_methods(target_method, scope)
|
333
|
+
hooks[target_method][:in].class_eval{define_advised_method(target_method, scope)}
|
334
|
+
end
|
335
|
+
else
|
336
|
+
register_hook(target_method, scope)
|
337
|
+
hooks = hooks_with_scope(scope)
|
338
|
+
end
|
321
339
|
|
340
|
+
#if we were passed a block, create a method out of it.
|
322
341
|
if block
|
323
342
|
method_sym = "__hooks_#{type}_#{quote_method(target_method)}_#{hooks[target_method][type].length}".to_sym
|
324
343
|
if scope == :class
|
325
|
-
|
344
|
+
meta_class.instance_eval do
|
326
345
|
define_method(method_sym, &block)
|
327
346
|
end
|
328
347
|
else
|
data/lib/extlib/lazy_array.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
class LazyArray # borrowed partially from StrokeDB
|
2
2
|
instance_methods.each { |m| undef_method m unless %w[ __id__ __send__ send class dup object_id kind_of? respond_to? equal? assert_kind_of should should_not instance_variable_set instance_variable_get extend ].include?(m.to_s) }
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def first(*args)
|
9
|
-
if lazy_possible?(@head, *args)
|
10
|
-
@head.first(*args)
|
11
|
-
else
|
4
|
+
# add proxies for all Array and Enumerable methods
|
5
|
+
((Array.instance_methods(false) | Enumerable.instance_methods(false)).map { |m| m.to_s } - %w[ taguri= ]).each do |method|
|
6
|
+
class_eval <<-EOS, __FILE__, __LINE__
|
7
|
+
def #{method}(*args, &block)
|
12
8
|
lazy_load
|
13
|
-
@array
|
14
|
-
|
15
|
-
end
|
16
|
-
else
|
17
|
-
def first(*args)
|
18
|
-
if lazy_possible?(@head, *args)
|
19
|
-
@head.first(*args)
|
20
|
-
else
|
21
|
-
super
|
9
|
+
results = @array.#{method}(*args, &block)
|
10
|
+
results.equal?(@array) ? self : results
|
22
11
|
end
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def first(*args)
|
16
|
+
if lazy_possible?(@head, *args)
|
17
|
+
@head.first(*args)
|
18
|
+
else
|
19
|
+
lazy_load
|
20
|
+
@array.first(*args)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -27,7 +25,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
27
25
|
if lazy_possible?(@tail, *args)
|
28
26
|
@tail.last(*args)
|
29
27
|
else
|
30
|
-
|
28
|
+
lazy_load
|
29
|
+
@array.last(*args)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
@@ -37,7 +36,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
37
36
|
elsif index < 0 && lazy_possible?(@tail, index.abs)
|
38
37
|
@tail.at(index)
|
39
38
|
else
|
40
|
-
|
39
|
+
lazy_load
|
40
|
+
@array.at(index)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -49,7 +49,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
49
49
|
elsif index < 0 && lazy_possible?(@tail, index.abs)
|
50
50
|
@tail.fetch(*args, &block)
|
51
51
|
else
|
52
|
-
|
52
|
+
lazy_load
|
53
|
+
@array.fetch(*args, &block)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -69,28 +70,36 @@ class LazyArray # borrowed partially from StrokeDB
|
|
69
70
|
if lazy_possible
|
70
71
|
accumulator
|
71
72
|
else
|
72
|
-
|
73
|
+
lazy_load
|
74
|
+
@array.values_at(*args)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
78
|
def index(entry)
|
77
|
-
(lazy_possible?(@head) && @head.index(entry)) ||
|
79
|
+
(lazy_possible?(@head) && @head.index(entry)) || begin
|
80
|
+
lazy_load
|
81
|
+
@array.index(entry)
|
82
|
+
end
|
78
83
|
end
|
79
84
|
|
80
85
|
def include?(entry)
|
81
86
|
(lazy_possible?(@tail) && @tail.include?(entry)) ||
|
82
|
-
(lazy_possible?(@head) && @head.include?(entry)) ||
|
83
|
-
|
87
|
+
(lazy_possible?(@head) && @head.include?(entry)) || begin
|
88
|
+
lazy_load
|
89
|
+
@array.include?(entry)
|
90
|
+
end
|
84
91
|
end
|
85
92
|
|
86
93
|
def empty?
|
87
94
|
!any?
|
88
95
|
end
|
89
96
|
|
90
|
-
def any?
|
91
|
-
(lazy_possible?(@tail) && @tail.any?) ||
|
92
|
-
(lazy_possible?(@head) && @head.any?) ||
|
93
|
-
|
97
|
+
def any?(&block)
|
98
|
+
(lazy_possible?(@tail) && @tail.any?(&block)) ||
|
99
|
+
(lazy_possible?(@head) && @head.any?(&block)) || begin
|
100
|
+
lazy_load
|
101
|
+
@array.any?(&block)
|
102
|
+
end
|
94
103
|
end
|
95
104
|
|
96
105
|
def [](*args)
|
@@ -103,11 +112,12 @@ class LazyArray # borrowed partially from StrokeDB
|
|
103
112
|
length ||= 1
|
104
113
|
|
105
114
|
if index >= 0 && lazy_possible?(@head, index + length)
|
106
|
-
@head
|
115
|
+
@head[*args]
|
107
116
|
elsif index < 0 && lazy_possible?(@tail, index.abs - 1 + length)
|
108
|
-
@tail
|
117
|
+
@tail[*args]
|
109
118
|
else
|
110
|
-
|
119
|
+
lazy_load
|
120
|
+
@array[*args]
|
111
121
|
end
|
112
122
|
end
|
113
123
|
|
@@ -123,7 +133,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
123
133
|
elsif index < 0 && lazy_possible?(@tail, index.abs - 1 + length)
|
124
134
|
@tail.slice!(*args)
|
125
135
|
else
|
126
|
-
|
136
|
+
lazy_load
|
137
|
+
@array.slice!(*args)
|
127
138
|
end
|
128
139
|
end
|
129
140
|
|
@@ -137,7 +148,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
137
148
|
elsif index < 0 && lazy_possible?(@tail, index.abs - 1 + length)
|
138
149
|
@tail.[]=(*args)
|
139
150
|
else
|
140
|
-
|
151
|
+
lazy_load
|
152
|
+
@array.[]=(*args)
|
141
153
|
end
|
142
154
|
end
|
143
155
|
|
@@ -167,7 +179,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
167
179
|
|
168
180
|
def <<(entry)
|
169
181
|
if loaded?
|
170
|
-
|
182
|
+
lazy_load
|
183
|
+
@array << entry
|
171
184
|
else
|
172
185
|
@tail << entry
|
173
186
|
end
|
@@ -178,16 +191,18 @@ class LazyArray # borrowed partially from StrokeDB
|
|
178
191
|
|
179
192
|
def concat(other)
|
180
193
|
if loaded?
|
181
|
-
|
194
|
+
lazy_load
|
195
|
+
@array.concat(other)
|
182
196
|
else
|
183
|
-
@tail.concat(other
|
197
|
+
@tail.concat(other)
|
184
198
|
end
|
185
199
|
self
|
186
200
|
end
|
187
201
|
|
188
202
|
def push(*entries)
|
189
203
|
if loaded?
|
190
|
-
|
204
|
+
lazy_load
|
205
|
+
@array.push(*entries)
|
191
206
|
else
|
192
207
|
@tail.push(*entries)
|
193
208
|
end
|
@@ -196,7 +211,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
196
211
|
|
197
212
|
def unshift(*entries)
|
198
213
|
if loaded?
|
199
|
-
|
214
|
+
lazy_load
|
215
|
+
@array.unshift(*entries)
|
200
216
|
else
|
201
217
|
@head.unshift(*entries)
|
202
218
|
end
|
@@ -209,7 +225,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
209
225
|
elsif index < 0 && lazy_possible?(@tail, index.abs - 1)
|
210
226
|
@tail.insert(index, *entries)
|
211
227
|
else
|
212
|
-
|
228
|
+
lazy_load
|
229
|
+
@array.insert(index, *entries)
|
213
230
|
end
|
214
231
|
self
|
215
232
|
end
|
@@ -218,7 +235,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
218
235
|
if lazy_possible?(@tail)
|
219
236
|
@tail.pop
|
220
237
|
else
|
221
|
-
|
238
|
+
lazy_load
|
239
|
+
@array.pop
|
222
240
|
end
|
223
241
|
end
|
224
242
|
|
@@ -226,7 +244,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
226
244
|
if lazy_possible?(@head)
|
227
245
|
@head.shift
|
228
246
|
else
|
229
|
-
|
247
|
+
lazy_load
|
248
|
+
@array.shift
|
230
249
|
end
|
231
250
|
end
|
232
251
|
|
@@ -236,13 +255,15 @@ class LazyArray # borrowed partially from StrokeDB
|
|
236
255
|
elsif index < 0 && lazy_possible?(@tail, index.abs)
|
237
256
|
@tail.delete_at(index)
|
238
257
|
else
|
239
|
-
|
258
|
+
lazy_load
|
259
|
+
@array.delete_at(index)
|
240
260
|
end
|
241
261
|
end
|
242
262
|
|
243
263
|
def delete_if(&block)
|
244
264
|
if loaded?
|
245
|
-
|
265
|
+
lazy_load
|
266
|
+
@array.delete_if(&block)
|
246
267
|
else
|
247
268
|
@reapers ||= []
|
248
269
|
@reapers << block
|
@@ -254,7 +275,7 @@ class LazyArray # borrowed partially from StrokeDB
|
|
254
275
|
|
255
276
|
def replace(other)
|
256
277
|
mark_loaded
|
257
|
-
@array.replace(other
|
278
|
+
@array.replace(other)
|
258
279
|
self
|
259
280
|
end
|
260
281
|
|
@@ -284,6 +305,8 @@ class LazyArray # borrowed partially from StrokeDB
|
|
284
305
|
super || @array.kind_of?(klass)
|
285
306
|
end
|
286
307
|
|
308
|
+
alias is_a? kind_of?
|
309
|
+
|
287
310
|
def respond_to?(method, include_private = false)
|
288
311
|
super || @array.respond_to?(method)
|
289
312
|
end
|
@@ -304,11 +327,58 @@ class LazyArray # borrowed partially from StrokeDB
|
|
304
327
|
end
|
305
328
|
|
306
329
|
def eql?(other)
|
307
|
-
|
308
|
-
|
330
|
+
return true if equal?(other)
|
331
|
+
return false unless other.class.equal?(self.class)
|
332
|
+
|
333
|
+
unless loaded?
|
334
|
+
# compare the head against the beginning of other. start at index
|
335
|
+
# 0 and incrementally compare each entry. if other is a LazyArray
|
336
|
+
# this has a lesser likelyhood of triggering a lazy load
|
337
|
+
0.upto(@head.size - 1) do |i|
|
338
|
+
return false unless @head[i].eql?(other[i])
|
339
|
+
end
|
340
|
+
|
341
|
+
# compare the tail against the end of other. start at index
|
342
|
+
# -1 and decrementally compare each entry. if other is a LazyArray
|
343
|
+
# this has a lesser likelyhood of triggering a lazy load
|
344
|
+
-1.downto(@tail.size * -1) do |i|
|
345
|
+
return false unless @tail[i].eql?(other[i])
|
346
|
+
end
|
347
|
+
|
348
|
+
lazy_load
|
349
|
+
end
|
350
|
+
|
351
|
+
# convert other to an Array before checking equality
|
352
|
+
@array.eql?(other.to_ary)
|
309
353
|
end
|
310
354
|
|
311
|
-
|
355
|
+
def ==(other)
|
356
|
+
return true if equal?(other)
|
357
|
+
return false unless other.respond_to?(:to_ary)
|
358
|
+
|
359
|
+
# if necessary, convert to something that can be compared
|
360
|
+
other = other.to_ary unless other.respond_to?(:[])
|
361
|
+
|
362
|
+
unless loaded?
|
363
|
+
# compare the head against the beginning of other. start at index
|
364
|
+
# 0 and incrementally compare each entry. if other is a LazyArray
|
365
|
+
# this has a lesser likelyhood of triggering a lazy load
|
366
|
+
0.upto(@head.size - 1) do |i|
|
367
|
+
return false unless @head[i] == other[i]
|
368
|
+
end
|
369
|
+
|
370
|
+
# compare the tail against the end of other. start at index
|
371
|
+
# -1 and decrementally compare each entry. if other is a LazyArray
|
372
|
+
# this has a lesser likelyhood of triggering a lazy load
|
373
|
+
-1.downto(@tail.size * -1) do |i|
|
374
|
+
return false unless @tail[i] == other[i]
|
375
|
+
end
|
376
|
+
|
377
|
+
lazy_load
|
378
|
+
end
|
379
|
+
|
380
|
+
@array == other
|
381
|
+
end
|
312
382
|
|
313
383
|
protected
|
314
384
|
|
data/lib/extlib/module.rb
CHANGED
@@ -30,7 +30,11 @@ class Module
|
|
30
30
|
constants.each do |const|
|
31
31
|
# return the nested constant if available
|
32
32
|
return const if parts.all? do |part|
|
33
|
-
const =
|
33
|
+
const = if RUBY_VERSION >= '1.9.0'
|
34
|
+
const.const_defined?(part, false) ? const.const_get(part, false) : nil
|
35
|
+
else
|
36
|
+
const.const_defined?(part) ? const.const_get(part) : nil
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
data/lib/extlib/version.rb
CHANGED
data/spec/class_spec.rb
CHANGED
@@ -18,6 +18,14 @@ class Grandparent
|
|
18
18
|
self._attribute = 1900
|
19
19
|
end
|
20
20
|
|
21
|
+
class ClassWithInheritableSymbolAccessor
|
22
|
+
class_inheritable_accessor :symbol
|
23
|
+
self.symbol = :foo
|
24
|
+
end
|
25
|
+
|
26
|
+
class ClassInheritingSymbolAccessor < ClassWithInheritableSymbolAccessor
|
27
|
+
end
|
28
|
+
|
21
29
|
describe Class, "#inheritable_accessor" do
|
22
30
|
|
23
31
|
after :each do
|
@@ -104,6 +112,14 @@ describe Class, "#inheritable_accessor" do
|
|
104
112
|
|
105
113
|
end
|
106
114
|
|
115
|
+
describe Class, "#inheritable_accessor (of type Symbol)" do
|
116
|
+
|
117
|
+
it "should not raise" do
|
118
|
+
lambda { ClassInheritingSymbolAccessor.symbol }.should_not raise_error(TypeError)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
107
123
|
#
|
108
124
|
# The bug that prompted this estoric spec was found in
|
109
125
|
# the wild when using dm-is-versioned with c_i_w.
|
@@ -132,10 +148,10 @@ end
|
|
132
148
|
|
133
149
|
describe Class, "#inheritable_accessor" do
|
134
150
|
it "uses object_id for comparison" do
|
135
|
-
Model.methods.should include("plugin_options")
|
151
|
+
Model.methods.map { |m| m.to_s }.should include("plugin_options")
|
136
152
|
Model.plugin_options.should == :foo
|
137
153
|
|
138
|
-
Model::Version.methods.should include("plugin_options")
|
154
|
+
Model::Version.methods.map { |m| m.to_s }.should include("plugin_options")
|
139
155
|
Model::Version.plugin_options.should == :foo
|
140
156
|
end
|
141
157
|
end
|
data/spec/hook_spec.rb
CHANGED
@@ -779,6 +779,34 @@ describe Extlib::Hook do
|
|
779
779
|
inst.should_not_receive(:hello_world!)
|
780
780
|
inst.hookable
|
781
781
|
end
|
782
|
+
|
783
|
+
it 'should call different hooks in different children when they are defined there' do
|
784
|
+
@class.send(:define_method, :hello_world) {}
|
785
|
+
|
786
|
+
@child1 = Class.new(@class) do
|
787
|
+
before(:hello_world){ hi_dad! }
|
788
|
+
end
|
789
|
+
|
790
|
+
@child2 = Class.new(@class) do
|
791
|
+
before(:hello_world){ hi_mom! }
|
792
|
+
end
|
793
|
+
|
794
|
+
@child3 = Class.new(@child1) do
|
795
|
+
before(:hello_world){ hi_grandma! }
|
796
|
+
end
|
797
|
+
|
798
|
+
inst1 = @child1.new
|
799
|
+
inst2 = @child2.new
|
800
|
+
inst3 = @child3.new
|
801
|
+
inst1.should_receive(:hi_dad!).once
|
802
|
+
inst2.should_receive(:hi_mom!).once
|
803
|
+
inst3.should_receive(:hi_dad!).once
|
804
|
+
inst3.should_receive(:hi_grandma!).once
|
805
|
+
inst1.hello_world
|
806
|
+
inst2.hello_world
|
807
|
+
inst3.hello_world
|
808
|
+
end
|
809
|
+
|
782
810
|
end
|
783
811
|
|
784
812
|
end
|
data/spec/lazy_array_spec.rb
CHANGED
@@ -44,7 +44,7 @@ module LazyArraySpec
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should eql self' do
|
47
|
-
action.should eql(subject
|
47
|
+
action.should eql(subject)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -176,42 +176,72 @@ end
|
|
176
176
|
should_respond_to(:any?)
|
177
177
|
|
178
178
|
describe '#any?', state do
|
179
|
-
describe 'when
|
179
|
+
describe 'when not provided a block' do
|
180
180
|
action { subject.any? }
|
181
181
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
182
|
+
describe 'when the subject has entries that are not loaded' do
|
183
|
+
should_return_true
|
184
|
+
should_be_a_kicker
|
185
|
+
should_not_change_subject
|
186
|
+
end
|
186
187
|
|
187
|
-
|
188
|
-
|
188
|
+
describe 'when the subject has entries that are prepended' do
|
189
|
+
subject { LazyArray.new.unshift(@nancy) }
|
189
190
|
|
190
|
-
|
191
|
+
should_return_true
|
192
|
+
should_not_be_a_kicker
|
193
|
+
should_not_change_subject
|
194
|
+
end
|
191
195
|
|
192
|
-
|
193
|
-
|
194
|
-
should_not_change_subject
|
195
|
-
end
|
196
|
+
describe 'when the subject has entries that are appended' do
|
197
|
+
subject { LazyArray.new << @nancy }
|
196
198
|
|
197
|
-
|
198
|
-
|
199
|
+
should_return_true
|
200
|
+
should_not_be_a_kicker
|
201
|
+
should_not_change_subject
|
202
|
+
end
|
199
203
|
|
200
|
-
|
204
|
+
describe 'when the subject has no entries' do
|
205
|
+
subject { LazyArray.new }
|
201
206
|
|
202
|
-
|
203
|
-
|
204
|
-
|
207
|
+
should_return_false
|
208
|
+
should_be_a_kicker
|
209
|
+
should_not_change_subject
|
210
|
+
end
|
205
211
|
end
|
206
212
|
|
207
|
-
describe 'when
|
208
|
-
|
213
|
+
describe 'when provided a block that always returns true' do
|
214
|
+
action { subject.any? { true } }
|
209
215
|
|
210
|
-
|
216
|
+
describe 'when the subject has entries that are not loaded' do
|
217
|
+
should_return_true
|
218
|
+
should_be_a_kicker
|
219
|
+
should_not_change_subject
|
220
|
+
end
|
211
221
|
|
212
|
-
|
213
|
-
|
214
|
-
|
222
|
+
describe 'when the subject has entries that are prepended' do
|
223
|
+
subject { LazyArray.new.unshift(@nancy) }
|
224
|
+
|
225
|
+
should_return_true
|
226
|
+
should_not_be_a_kicker
|
227
|
+
should_not_change_subject
|
228
|
+
end
|
229
|
+
|
230
|
+
describe 'when the subject has entries that are appended' do
|
231
|
+
subject { LazyArray.new << @nancy }
|
232
|
+
|
233
|
+
should_return_true
|
234
|
+
should_not_be_a_kicker
|
235
|
+
should_not_change_subject
|
236
|
+
end
|
237
|
+
|
238
|
+
describe 'when the subject has no entries' do
|
239
|
+
subject { LazyArray.new }
|
240
|
+
|
241
|
+
should_return_false
|
242
|
+
should_be_a_kicker
|
243
|
+
should_not_change_subject
|
244
|
+
end
|
215
245
|
end
|
216
246
|
end
|
217
247
|
|
@@ -472,7 +502,7 @@ end
|
|
472
502
|
describe '#each_with_index', state do
|
473
503
|
before { @accumulator = [] }
|
474
504
|
|
475
|
-
action { subject.each_with_index {
|
505
|
+
action { subject.each_with_index { |entry,index| @accumulator << [ entry, index ] } }
|
476
506
|
|
477
507
|
should_return_subject
|
478
508
|
should_be_a_kicker
|
@@ -525,23 +555,54 @@ end
|
|
525
555
|
end
|
526
556
|
end
|
527
557
|
|
528
|
-
|
558
|
+
[ :eql?, :== ].each do |method|
|
559
|
+
should_respond_to(method)
|
529
560
|
|
530
|
-
|
531
|
-
|
532
|
-
|
561
|
+
describe "##{method}", state do
|
562
|
+
describe 'with an Enumerable containing the same entries' do
|
563
|
+
before do
|
564
|
+
if method == :eql?
|
565
|
+
@other = LazyArray.new
|
566
|
+
@other.load_with { |la| la.push(@nancy, @bessie) }
|
567
|
+
else
|
568
|
+
@other = [ @nancy, @bessie ]
|
569
|
+
end
|
570
|
+
end
|
533
571
|
|
534
|
-
|
535
|
-
should_be_a_kicker
|
536
|
-
should_not_change_subject
|
537
|
-
end
|
572
|
+
action { subject.send(method, @other) }
|
538
573
|
|
539
|
-
|
540
|
-
|
574
|
+
should_return_true
|
575
|
+
should_be_a_kicker
|
576
|
+
should_not_change_subject
|
577
|
+
end
|
541
578
|
|
542
|
-
|
543
|
-
|
544
|
-
|
579
|
+
describe 'with an Enumerable containing different entries' do
|
580
|
+
action { subject.send(method, @other) }
|
581
|
+
|
582
|
+
should_return_false
|
583
|
+
should_be_a_kicker
|
584
|
+
should_not_change_subject
|
585
|
+
end
|
586
|
+
|
587
|
+
describe 'with an Enumerable with different entries than in head' do
|
588
|
+
before { subject.unshift(@nancy) }
|
589
|
+
|
590
|
+
action { subject.send(method, [ @steve ]) }
|
591
|
+
|
592
|
+
should_return_false
|
593
|
+
should_not_be_a_kicker
|
594
|
+
should_not_change_subject
|
595
|
+
end
|
596
|
+
|
597
|
+
describe 'with an Enumerable with different entries than in tail' do
|
598
|
+
before { subject.push(@nancy) }
|
599
|
+
|
600
|
+
action { subject.send(method, [ @steve ]) }
|
601
|
+
|
602
|
+
should_return_false
|
603
|
+
should_not_be_a_kicker
|
604
|
+
should_not_change_subject
|
605
|
+
end
|
545
606
|
end
|
546
607
|
end
|
547
608
|
|
@@ -1008,7 +1069,7 @@ end
|
|
1008
1069
|
should_not_change_subject
|
1009
1070
|
|
1010
1071
|
it 'should return a reversed LazyArray' do
|
1011
|
-
action.should
|
1072
|
+
action.should == [ @bessie, @nancy ]
|
1012
1073
|
end
|
1013
1074
|
end
|
1014
1075
|
|
@@ -1021,7 +1082,7 @@ end
|
|
1021
1082
|
should_not_be_a_kicker
|
1022
1083
|
|
1023
1084
|
it 'should return a reversed LazyArray' do
|
1024
|
-
action.should
|
1085
|
+
action.should == [ @bessie, @nancy ]
|
1025
1086
|
end
|
1026
1087
|
end
|
1027
1088
|
|
@@ -1727,8 +1788,11 @@ end
|
|
1727
1788
|
action { subject.to_a }
|
1728
1789
|
|
1729
1790
|
should_return_kind_of(Array)
|
1730
|
-
should_return_copy
|
1731
1791
|
should_be_a_kicker
|
1792
|
+
|
1793
|
+
it 'should be equivalent to self' do
|
1794
|
+
action.should == subject
|
1795
|
+
end
|
1732
1796
|
end
|
1733
1797
|
|
1734
1798
|
should_respond_to(:unshift)
|
data/spec/module_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
|
3
3
|
describe Module do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
-
module Foo
|
6
|
+
module ::Foo
|
7
7
|
module ModBar
|
8
8
|
module Noo
|
9
9
|
module Too
|
@@ -15,10 +15,10 @@ describe Module do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
class Baz
|
18
|
+
class ::Baz
|
19
19
|
end
|
20
20
|
|
21
|
-
class Bar
|
21
|
+
class ::Bar
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -51,7 +51,7 @@ describe Module do
|
|
51
51
|
it "should be able to deal with constants being added and removed" do
|
52
52
|
Object.find_const('Bar') # First we load Bar with find_const
|
53
53
|
Object.module_eval { remove_const('Bar') } # Now we delete it
|
54
|
-
module Bar; end; # Now we redefine it
|
54
|
+
module ::Bar; end; # Now we redefine it
|
55
55
|
Object.find_const('Bar').should == Bar
|
56
56
|
end
|
57
57
|
|
data/spec/pooling_spec.rb
CHANGED
@@ -146,7 +146,7 @@ describe "Extlib::Pooling" do
|
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should wake up the scavenger thread when exiting" do
|
149
|
-
pending 'Fix for
|
149
|
+
pending 'Fix for JRuby' if RUBY_PLATFORM =~ /java/
|
150
150
|
bob = Person.new('Bob')
|
151
151
|
bob.release
|
152
152
|
Extlib.exiting = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Smoot
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-19 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|