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.
@@ -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 ! instance.is_a?( ::Module )
148
+ if parents.empty? and instance != ::Class
149
149
 
150
- ancestor_instance = instance.class
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
- matched_value = nil
328
+ matched_ancestor = nil
327
329
 
328
330
  this_ancestor = instance
329
331
 
330
- if this_ancestor.is_a?( ::Module ) or
331
- has_parents?( this_ancestor )
332
-
332
+ if has_parents?( this_ancestor )
333
+
333
334
  begin
334
335
  if match_block.call( this_ancestor )
335
- matched_value = this_ancestor
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
- matched_value = this_ancestor
344
+ matched_ancestor = this_ancestor
343
345
 
344
346
  else
345
347
 
346
- matched_value = match_ancestor( this_ancestor.class,
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 matched_value
351
+
352
+ return matched_ancestor
353
353
 
354
354
  end
355
355
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel-ancestry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: