simple_tree 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,4 +4,7 @@
4
4
 
5
5
  ## v0.0.2
6
6
  * Added spec coverage
7
- * Fixed a bug with descendants method
7
+ * Fixed a bug with descendants method
8
+
9
+ ## v0.0.3
10
+ * Added more api that supported by awesome_nested_set
@@ -27,6 +27,11 @@ module SimpleTree
27
27
  nodes
28
28
  end
29
29
 
30
+ def self_and_ancestors
31
+ nodes = [] << self
32
+ nodes += self.ancestors
33
+ end
34
+
30
35
  # Returns the root node of the tree.
31
36
  def root
32
37
  node = self
@@ -34,6 +39,13 @@ module SimpleTree
34
39
  node
35
40
  end
36
41
 
42
+ def root?
43
+ self.root == self
44
+ end
45
+
46
+ def child?
47
+ self.parent != nil
48
+ end
37
49
  # Returns all siblings of the current node.
38
50
  #
39
51
  # subchild1.siblings # => [subchild2]
@@ -55,9 +67,15 @@ module SimpleTree
55
67
  nodes
56
68
  end
57
69
 
70
+ def self_and_descendants
71
+ node = [] << self
72
+ node += self.descendants
73
+ end
74
+
58
75
  def move_to_child_of(parent)
59
76
  self.parent = parent
60
77
  end
61
78
 
79
+
62
80
  end
63
81
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleTree
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = SimpleTree::VERSION
8
8
  s.authors = ["yinghai"]
9
9
  s.email = ["yinghai.zhao@mosaic.com"]
10
- s.homepage = ""
10
+ s.homepage = "http://github.com/mosaicxm/simple-tree"
11
11
  s.summary = %q{simple tree gem}
12
12
  s.description = %q{simple tree gem}
13
13
 
@@ -33,6 +33,13 @@ describe SimpleTree do
33
33
  @gc1a.ancestors.should == [@c1,@root]
34
34
  end
35
35
  end
36
+
37
+ describe "#self_and_ancestors" do
38
+ it "should return all ancestors including self" do
39
+ @gc1a.self_and_ancestors.should == [@gc1a,@c1,@root]
40
+ end
41
+ end
42
+
36
43
  describe "#root" do
37
44
  it "should return root for descendants" do
38
45
  @gc1a.root.should == @root
@@ -65,6 +72,30 @@ describe SimpleTree do
65
72
  end
66
73
  end
67
74
 
75
+ describe '#self_and_descendants' do
76
+ it "should return all descendants including self" do
77
+ @root.self_and_descendants.should == [@root,@c1,@c2,@gc1a,@gc2a]
78
+ end
79
+ end
80
+
81
+ describe '#root?' do
82
+ it "should return true for root" do
83
+ @root.root?.should be_true
84
+ end
85
+ it "should return false for child" do
86
+ @c1.root?.should be_false
87
+ end
88
+ end
89
+
90
+ describe '#child?' do
91
+ it "should return true for root" do
92
+ @root.child?.should be_false
93
+ end
94
+ it "should return false for child" do
95
+ @c1.child?.should be_true
96
+ end
97
+ end
98
+
68
99
  describe '#move_to_child_of' do
69
100
  it "should move a branch to it's new parents" do
70
101
  @gc2a.move_to_child_of(@root)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70132630472340 !ruby/object:Gem::Requirement
16
+ requirement: &70157905429500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70132630472340
24
+ version_requirements: *70157905429500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: with_model
27
- requirement: &70132630471920 !ruby/object:Gem::Requirement
27
+ requirement: &70157905428380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70132630471920
35
+ version_requirements: *70157905428380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70132630471400 !ruby/object:Gem::Requirement
38
+ requirement: &70157906087240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.0.9
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70132630471400
46
+ version_requirements: *70157906087240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &70132630470980 !ruby/object:Gem::Requirement
49
+ requirement: &70157906086820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70132630470980
57
+ version_requirements: *70157906086820
58
58
  description: simple tree gem
59
59
  email:
60
60
  - yinghai.zhao@mosaic.com
@@ -73,7 +73,7 @@ files:
73
73
  - simple_tree.gemspec
74
74
  - spec/simple_tree_spec.rb
75
75
  - spec/spec_helper.rb
76
- homepage: ''
76
+ homepage: http://github.com/mosaicxm/simple-tree
77
77
  licenses: []
78
78
  post_install_message:
79
79
  rdoc_options: []