parallel-ancestry 1.0.3 → 1.0.4
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/CHANGELOG.rdoc +1 -0
- data/lib/parallel-ancestry/ParallelAncestry.rb +19 -19
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
@@ -12,3 +12,4 @@ Shortened :initialize_base_instance_for_include and :initialize_base_instance_fo
|
|
12
12
|
== 6/12/2012
|
13
13
|
|
14
14
|
Renamed :match_ancestor_searching_upward to :match_ancestor because ancestors are always found by searching upward.
|
15
|
+
Fixes for ancestor lookup when arriving at Class.
|
@@ -145,10 +145,13 @@ module ::ParallelAncestry
|
|
145
145
|
# If we don't have ancestors explicitly declared for this instance, and if it is not
|
146
146
|
# a ::Class or ::Module (both are ::Modules) then we have an instance of a class,
|
147
147
|
# so we can use the instance's class
|
148
|
-
if parents.empty? and
|
148
|
+
if parents.empty? and instance != ::Class
|
149
149
|
|
150
|
-
|
151
|
-
|
150
|
+
instance_class = instance.class
|
151
|
+
if match_ancestor_block.call( instance_class )
|
152
|
+
ancestor_instance = instance.class
|
153
|
+
end
|
154
|
+
|
152
155
|
else
|
153
156
|
|
154
157
|
parents.each do |this_parent|
|
@@ -293,9 +296,9 @@ module ::ParallelAncestry
|
|
293
296
|
|
294
297
|
end
|
295
298
|
|
296
|
-
|
299
|
+
####################
|
297
300
|
# match_ancestor #
|
298
|
-
|
301
|
+
####################
|
299
302
|
|
300
303
|
# Returns the first ancestor (determined by ancestor_match_block) for which match_block is true.
|
301
304
|
# @param [Object] instance Instance for which parents are being looked up.
|
@@ -312,8 +315,7 @@ module ::ParallelAncestry
|
|
312
315
|
# false
|
313
316
|
# end
|
314
317
|
# end
|
315
|
-
# ::ParallelAncestry.match_ancestor( some_instance,
|
316
|
-
# ancestor_match_block ) do |this_parent|
|
318
|
+
# ::ParallelAncestry.match_ancestor( some_instance, ancestor_match_block ) do |this_parent|
|
317
319
|
# if this_parent.matches_arbitrary_condition
|
318
320
|
# true
|
319
321
|
# else
|
@@ -323,33 +325,31 @@ module ::ParallelAncestry
|
|
323
325
|
# @return [Object]
|
324
326
|
def match_ancestor( instance, ancestor_match_block, & match_block )
|
325
327
|
|
326
|
-
|
328
|
+
matched_ancestor = nil
|
327
329
|
|
328
330
|
this_ancestor = instance
|
329
331
|
|
330
|
-
if
|
331
|
-
|
332
|
-
|
332
|
+
if has_parents?( this_ancestor )
|
333
|
+
|
333
334
|
begin
|
334
335
|
if match_block.call( this_ancestor )
|
335
|
-
|
336
|
+
matched_ancestor = this_ancestor
|
336
337
|
break
|
337
338
|
end
|
339
|
+
break if this_ancestor.equal?( ::Object )
|
338
340
|
end while this_ancestor = ancestor( this_ancestor, & ancestor_match_block )
|
339
|
-
|
341
|
+
|
340
342
|
elsif match_block.call( this_ancestor )
|
341
343
|
|
342
|
-
|
344
|
+
matched_ancestor = this_ancestor
|
343
345
|
|
344
346
|
else
|
345
347
|
|
346
|
-
|
347
|
-
ancestor_match_block,
|
348
|
-
& match_block )
|
348
|
+
matched_ancestor = match_ancestor( this_ancestor.class, ancestor_match_block, & match_block )
|
349
349
|
|
350
350
|
end
|
351
|
-
|
352
|
-
return
|
351
|
+
|
352
|
+
return matched_ancestor
|
353
353
|
|
354
354
|
end
|
355
355
|
|