acts_as_tree 1.4.0 → 1.5.0
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/README.md +3 -0
- data/lib/acts_as_tree.rb +16 -1
- data/lib/acts_as_tree/version.rb +1 -1
- data/test/acts_as_tree_test.rb +10 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4b7ecba20760317473e4fe15ae47804ad57ff68
|
4
|
+
data.tar.gz: cface22965a3e581aded8ba0976226c11bcbcece
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10c6e09214046e11b68883211e46ddc1c8879771bb80ddd534eeba0466620f0d5c827f52378514af1db77add3464ca2c32b1207ab5b333a5062b015bd33e706f
|
7
|
+
data.tar.gz: 9cbf66c8158e7037a77167c9279d91c6978129b93c7ff47e65a67e01bd771e2973a50ebf3434e7bfb83fe9cdfde4ed0edce5d2b9c29ce7b01b5cfc0d7bf68298
|
data/README.md
CHANGED
@@ -51,6 +51,9 @@ We no longer support Ruby 1.8 or versions of Rails/ActiveRecord older than 3.0.
|
|
51
51
|
Moving forward we will do our best to support the latest versions of ActiveRecord and Ruby.
|
52
52
|
|
53
53
|
## Change Log
|
54
|
+
* 1.5.0 - December 16th, 2013
|
55
|
+
* `Added new descendants method` -- adamkleingit
|
56
|
+
* Fixed warning message -- akicho8
|
54
57
|
* 1.4.0 - June 25th, 2013
|
55
58
|
* `Presentation#tree_view` -- rainchen
|
56
59
|
* `root?` && `leaf?` methods. -- xuanxu
|
data/lib/acts_as_tree.rb
CHANGED
@@ -100,7 +100,6 @@ module ActsAsTree
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def self.root
|
103
|
-
order_option = %Q{#{configuration.fetch :order, "nil"}}
|
104
103
|
self.roots.first
|
105
104
|
end
|
106
105
|
EOV
|
@@ -149,6 +148,22 @@ module ActsAsTree
|
|
149
148
|
nodes
|
150
149
|
end
|
151
150
|
|
151
|
+
# Returns list of descendants, starting from current node, not including current node.
|
152
|
+
#
|
153
|
+
# root.descendants # => [child1, child2, subchild1, subchild2, subchild3, subchild4]
|
154
|
+
def descendants
|
155
|
+
children.each_with_object(children) {|child, arr|
|
156
|
+
arr.concat child.descendants
|
157
|
+
}.uniq
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns list of descendants, starting from current node, including current node.
|
161
|
+
#
|
162
|
+
# root.self_and_descendants # => [root, child1, child2, subchild1, subchild2, subchild3, subchild4]
|
163
|
+
def self_and_descendants
|
164
|
+
[self] + descendants
|
165
|
+
end
|
166
|
+
|
152
167
|
# Returns the root node of the tree.
|
153
168
|
def root
|
154
169
|
node = self
|
data/lib/acts_as_tree/version.rb
CHANGED
data/test/acts_as_tree_test.rb
CHANGED
@@ -166,6 +166,16 @@ class TreeTest < Test::Unit::TestCase
|
|
166
166
|
assert_equal [@root2], @root2.self_and_ancestors
|
167
167
|
end
|
168
168
|
|
169
|
+
def test_self_and_descendants
|
170
|
+
assert_equal [@root1, @root_child1, @root_child2, @child1_child, @child1_child_child], @root1.self_and_descendants
|
171
|
+
assert_equal [@root2], @root2.self_and_descendants
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_descendants
|
175
|
+
assert_equal [@root_child1, @root_child2, @child1_child, @child1_child_child], @root1.descendants
|
176
|
+
assert_equal [], @root2.descendants
|
177
|
+
end
|
178
|
+
|
169
179
|
def test_nullify
|
170
180
|
root4 = TreeMixinNullify.create!
|
171
181
|
root4_child = TreeMixinNullify.create! parent_id: root4.id
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Dahlstrand
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -100,10 +100,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.1.10
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Provides a simple tree behaviour to active_record models.
|
107
107
|
test_files:
|
108
108
|
- test/acts_as_tree_test.rb
|
109
|
-
has_rdoc:
|