parallel-ancestry 1.0.4 → 1.0.5

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 CHANGED
@@ -13,3 +13,7 @@ Shortened :initialize_base_instance_for_include and :initialize_base_instance_fo
13
13
 
14
14
  Renamed :match_ancestor_searching_upward to :match_ancestor because ancestors are always found by searching upward.
15
15
  Fixes for ancestor lookup when arriving at Class.
16
+
17
+ == 6/15/2012
18
+
19
+ Added unique-array for children and parents, which means now :include? etc. use hash lookup internally.
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'module-cluster'
3
+ require 'unique-array'
3
4
 
4
5
  module ::ParallelAncestry
5
6
 
@@ -9,9 +10,10 @@ basepath = 'parallel-ancestry/ParallelAncestry'
9
10
 
10
11
  files = [
11
12
 
12
- 'ModuleSubclassInheritance',
13
13
  'Inheritance',
14
- 'Inheritance/ModuleSubclassInheritance'
14
+ 'Inheritance/ModuleSubclassInheritance',
15
+
16
+ 'ModuleSubclassInheritance'
15
17
 
16
18
  ]
17
19
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  module ::ParallelAncestry
3
3
 
4
- InstanceAncestryStruct = ::Struct.new( :children_hash, :parents_array, :parents_hash )
4
+ InstanceAncestryStruct = ::Struct.new( :children, :parents )
5
5
 
6
6
  extend ::ModuleCluster::Define::Block::ClassOrModule
7
7
 
@@ -32,7 +32,7 @@ module ::ParallelAncestry
32
32
  # @return [Array<Object>] An array containing references to children.
33
33
  def children( instance )
34
34
 
35
- return children_hash( instance ).keys
35
+ return ancestor_struct( instance ).children ||= ::UniqueArray.new( self )
36
36
 
37
37
  end
38
38
 
@@ -45,7 +45,7 @@ module ::ParallelAncestry
45
45
  # @return [Array<Object>] An array containing references to immediate parents for any configuration.
46
46
  def parents( instance )
47
47
 
48
- return parents_array( instance )
48
+ return ancestor_struct( instance ).parents ||= ::UniqueArray.new( self )
49
49
 
50
50
  end
51
51
 
@@ -58,15 +58,7 @@ module ::ParallelAncestry
58
58
  # @return [true, false] true or false.
59
59
  def has_parents?( instance )
60
60
 
61
- has_parents = false
62
-
63
- ancestor_struct = ancestor_struct( instance )
64
-
65
- if ancestor_struct.parents_array
66
- has_parents = ! ancestor_struct.parents_array.empty?
67
- end
68
-
69
- return has_parents
61
+ return ! parents( instance ).empty?
70
62
 
71
63
  end
72
64
 
@@ -79,15 +71,7 @@ module ::ParallelAncestry
79
71
  # @return [true, false] true or false.
80
72
  def has_children?( instance )
81
73
 
82
- has_children = false
83
-
84
- ancestor_struct = ancestor_struct( instance )
85
-
86
- if ancestor_struct.children_hash
87
- has_children = ! ancestor_struct.children_hash.empty?
88
- end
89
-
90
- return has_children
74
+ return ! children( instance ).empty?
91
75
 
92
76
  end
93
77
 
@@ -101,19 +85,14 @@ module ::ParallelAncestry
101
85
  # @return [Array<Object>] An array containing references to children.
102
86
  def register_child_for_parent( child, parent )
103
87
 
104
- parents_of_child_hash = parents_hash( child )
105
- children_of_parent_hash = children_hash( parent )
88
+ parents_of_child = parents( child )
89
+ children_of_parent = children( parent )
106
90
 
107
- unless children_of_parent_hash.has_key?( child )
108
- # child order shouldn't be relevant
109
- children_of_parent_hash[ child ] = true
110
- end
91
+ # child order shouldn't be relevant
92
+ children_of_parent.push( child )
111
93
 
112
- unless parents_of_child_hash.has_key?( parent )
113
- parents_of_child_hash[ parent ] = true
114
- # parent order determines who wins conflicts, so we keep youngest first
115
- parents_array( child ).unshift( parent )
116
- end
94
+ # parent order determines who wins conflicts, so we keep youngest first
95
+ parents_of_child.unshift( parent )
117
96
 
118
97
  return self
119
98
 
@@ -373,34 +352,4 @@ module ::ParallelAncestry
373
352
 
374
353
  end
375
354
 
376
- ###################
377
- # children_hash #
378
- ###################
379
-
380
- def children_hash( instance )
381
-
382
- return ancestor_struct( instance ).children_hash ||= { }
383
-
384
- end
385
-
386
- ##################
387
- # parents_hash #
388
- ##################
389
-
390
- def parents_hash( instance )
391
-
392
- return ancestor_struct( instance ).parents_hash ||= { }
393
-
394
- end
395
-
396
- ###################
397
- # parents_array #
398
- ###################
399
-
400
- def parents_array( instance )
401
-
402
- return ancestor_struct( instance ).parents_array ||= [ ]
403
-
404
- end
405
-
406
355
  end
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.4
4
+ version: 1.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-12 00:00:00.000000000 Z
12
+ date: 2012-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: module-cluster
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: unique-array
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Create and track parallel inheritance hierarchies. Hook parallel hierarchies
31
47
  (by including a module) to automatically update/register ancestry at include and
32
48
  extend, or update/register only manually. Manual registration permits definitions