rubytree 0.9.5pre2 → 0.9.5pre4
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/History.rdoc +12 -2
- data/README.md +2 -0
- data/TODO.org +4 -0
- data/lib/tree.rb +4 -3
- data/lib/tree/utils/metrics_methods.rb +1 -2
- data/lib/tree/version.rb +1 -1
- data/test/test_tree.rb +30 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a006133c7e37526b79f4256d041a29af0f34b04
|
4
|
+
data.tar.gz: 88eae77ba40ffc4a7a4e1e84bad59f25c3de0f91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f951cea5ef06e9419b19e17d07c821e6b8c09dd57cd6eafe0e2cee60e9d1293ae645165f2f66e90a7577536fef3ed2e5f8d1441dca9cd934c4bf6816e8e245a0
|
7
|
+
data.tar.gz: 5a6ae6fb1df04a15dbf11b8293a2e566482d0372af299b49c4c33778a50c1b2f159feb9606422ec1c539ca17594122fb954d08712cd01ce40c25f9cb06f0f7d1
|
data/Gemfile.lock
CHANGED
data/History.rdoc
CHANGED
@@ -2,11 +2,21 @@
|
|
2
2
|
|
3
3
|
= History of Changes
|
4
4
|
|
5
|
+
=== 0.9.5pre4 / 2014-12-17
|
6
|
+
|
7
|
+
* Added performance improvements to {Tree::TreeNode#is_root?} and
|
8
|
+
{Tree::TreeNode#node_depth}. Thanks to {https://github.com/aidansteele Aidan Steel}.
|
9
|
+
|
10
|
+
=== 0.9.5pre3 / 2014-12-16
|
11
|
+
|
12
|
+
* Minor fix to correct the release date. This release is otherwise identical to
|
13
|
+
0.9.5pre2.
|
14
|
+
|
5
15
|
=== 0.9.5pre2 / 2014-12-16
|
6
16
|
|
7
17
|
* Added {Tree::TreeNode#rename} and {Tree::TreeNode#rename_child} methods by
|
8
|
-
merging in code from {https://github.com/evolve75/RubyTree/pull/35}. Thanks
|
9
|
-
|
18
|
+
merging in code from {https://github.com/evolve75/RubyTree/pull/35}. Thanks to
|
19
|
+
{http://github.com/packetmonkey Evan Sharp}.
|
10
20
|
|
11
21
|
=== 0.9.5pre / 2014-11-01
|
12
22
|
|
data/README.md
CHANGED
@@ -213,6 +213,8 @@ A big thanks to the following contributors for helping improve **RubyTree**:
|
|
213
213
|
7. [Jen Hamon](http://www.github.com/jhamon) for adding the `from_hash` method.
|
214
214
|
8. [Evan Sharp](https://github.com/packetmonkey) for adding the `rename` and
|
215
215
|
`rename_child` methods.
|
216
|
+
9. [Aidan Steele](https://github.com/aidansteele) for performance improvements
|
217
|
+
to `is_root?` and `node_depth`.
|
216
218
|
|
217
219
|
|
218
220
|
## LICENSE: ##
|
data/TODO.org
CHANGED
@@ -187,6 +187,10 @@
|
|
187
187
|
|
188
188
|
|
189
189
|
* R0.9.5
|
190
|
+
** DONE Check the lazy initialization of =@node_depth= and changes in parent nodes :ARCHIVE:
|
191
|
+
CLOSED: [2014-12-18 Thu 11:05]
|
192
|
+
** DONE Pull the performance improvements from Aidan [[Pull:37][#37]] :ARCHIVE:
|
193
|
+
CLOSED: [2014-12-18 Thu 10:27]
|
190
194
|
** DONE Pull the =hash= converter code from [[https://github.com/markthomas/RubyTree/commits/master][Mark Thomas]] ([[Issue:13][Issue #13]]). :ARCHIVE:
|
191
195
|
CLOSED: [2014-11-01 Sat 20:10]
|
192
196
|
This was contributed by @jhamon.
|
data/lib/tree.rb
CHANGED
@@ -140,7 +140,7 @@ module Tree
|
|
140
140
|
#
|
141
141
|
# @return [Boolean] +true+ if this is a root node.
|
142
142
|
def is_root?
|
143
|
-
@parent
|
143
|
+
@parent.nil?
|
144
144
|
end
|
145
145
|
|
146
146
|
# @!attribute [r] has_content?
|
@@ -360,7 +360,7 @@ module Tree
|
|
360
360
|
def add(child, at_index = -1)
|
361
361
|
raise ArgumentError, "Attempting to add a nil node" unless child # Only handles the immediate child scenario
|
362
362
|
raise ArgumentError, "Attempting add node to itself" if self.equal?(child)
|
363
|
-
raise ArgumentError, "Attempting add root as a child" if
|
363
|
+
raise ArgumentError, "Attempting add root as a child" if child.equal?(root)
|
364
364
|
|
365
365
|
# Lazy mans unique test, won't test if children of child are unique in this tree too.
|
366
366
|
raise "Child #{child.name} already added!" if @children_hash.include?(child.name)
|
@@ -482,6 +482,7 @@ module Tree
|
|
482
482
|
# @return [Tree::TreeNode] The parent node.
|
483
483
|
def parent=(parent) # :nodoc:
|
484
484
|
@parent = parent
|
485
|
+
@node_depth = nil
|
485
486
|
end
|
486
487
|
|
487
488
|
protected :parent=, :name=
|
@@ -516,7 +517,7 @@ module Tree
|
|
516
517
|
#
|
517
518
|
# @return +nil+.
|
518
519
|
def set_as_root! # :nodoc:
|
519
|
-
|
520
|
+
self.parent = nil
|
520
521
|
end
|
521
522
|
|
522
523
|
protected :set_as_root!
|
data/lib/tree/version.rb
CHANGED
data/test/test_tree.rb
CHANGED
@@ -1470,11 +1470,7 @@ module TestTree
|
|
1470
1470
|
|
1471
1471
|
# And now a scenario where the node addition is done down the hierarchy
|
1472
1472
|
child = Tree::TreeNode.new("child")
|
1473
|
-
|
1474
|
-
root << child << root
|
1475
|
-
rescue ArgumentError => e
|
1476
|
-
fail("The ArgumentError should not have been raised.")
|
1477
|
-
end
|
1473
|
+
assert_raise(ArgumentError) { root << child << root }
|
1478
1474
|
end
|
1479
1475
|
|
1480
1476
|
# Test whether the tree_leaf method works correctly
|
@@ -1614,6 +1610,35 @@ module TestTree
|
|
1614
1610
|
assert_equal(@child1, @root['ALT_Child1'], 'Should be able to access from parent using new name')
|
1615
1611
|
|
1616
1612
|
end
|
1613
|
+
|
1614
|
+
def test_change_parent
|
1615
|
+
root_node = Tree::TreeNode.new("OLDROOT")
|
1616
|
+
|
1617
|
+
child_node = Tree::TreeNode.new("CHILD")
|
1618
|
+
assert_equal(child_node.node_depth, 0)
|
1619
|
+
|
1620
|
+
root_node << child_node
|
1621
|
+
assert_equal(root_node["CHILD"].name, "CHILD")
|
1622
|
+
assert_equal(root_node.node_depth, 0)
|
1623
|
+
assert_equal(child_node.node_depth, 1)
|
1624
|
+
|
1625
|
+
grandchild_node = Tree::TreeNode.new("GRANDCHILD")
|
1626
|
+
child_node << grandchild_node
|
1627
|
+
assert_equal(root_node["CHILD"]["GRANDCHILD"].name, "GRANDCHILD")
|
1628
|
+
assert_equal(root_node.node_depth, 0)
|
1629
|
+
assert_equal(child_node.node_depth, 1)
|
1630
|
+
assert_equal(grandchild_node.node_depth, 2)
|
1631
|
+
|
1632
|
+
root2_node = Tree::TreeNode.new("NEWROOT")
|
1633
|
+
assert_equal(root2_node.node_depth, 0)
|
1634
|
+
|
1635
|
+
# Move the grand child to a new root.
|
1636
|
+
root2_node << grandchild_node
|
1637
|
+
assert_equal(root2_node["GRANDCHILD"].name, "GRANDCHILD")
|
1638
|
+
assert_equal(grandchild_node.parent, root2_node)
|
1639
|
+
assert_equal(grandchild_node.node_depth, 1)
|
1640
|
+
|
1641
|
+
end
|
1617
1642
|
end
|
1618
1643
|
end
|
1619
1644
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubytree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5pre4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anupam Sengupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: structured_warnings
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: 1.3.1
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.4.3
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: A generic tree data structure.
|