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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6345f6c0aff0309193dc564612c75fc1ea6b267a
4
- data.tar.gz: 5d09b92e6dd13c1bf80be0f0b69d1cfb2c45328d
3
+ metadata.gz: f4b7ecba20760317473e4fe15ae47804ad57ff68
4
+ data.tar.gz: cface22965a3e581aded8ba0976226c11bcbcece
5
5
  SHA512:
6
- metadata.gz: 9c048a9ed2b95836a0915e1e95619975ef8bc4a42f7937bdfb258977f3ec4bf9420fc38eb9c5fa21abe7fd359dbb6861ad61d0f003339813c1114610ef5c782a
7
- data.tar.gz: 73fe82d6e696819c08633c5850ca1f1a4b588eb3033777df5bbd8331b2e4fc1de2dc636f5da1c5c9fb65fa9a9b8da4fc8740b69877bccd2c67386a199c2e8eb2
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
@@ -1,3 +1,3 @@
1
1
  module ActsAsTree
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -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.0
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-06-25 00:00:00.000000000 Z
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.0.0
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: