acts_as_tree 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/lib/acts_as_tree/railtie.rb +11 -0
- data/lib/acts_as_tree/version.rb +1 -1
- data/lib/acts_as_tree.rb +21 -31
- data/test/acts_as_tree_test.rb +5 -0
- metadata +25 -9
data/README.md
CHANGED
@@ -30,6 +30,9 @@ We no longer support Ruby 1.8 or versions if Rails/ActiveRecord older than 3.0.
|
|
30
30
|
Moving forward we will do our best to support the latest versions of ActiveRecord and Ruby.
|
31
31
|
|
32
32
|
## Change Log
|
33
|
+
* 1.2.0 - October 29th, 2012
|
34
|
+
* Adding new `self_with_ancestors` accessor -- fbuenemann
|
35
|
+
* `roots` is now a scope.
|
33
36
|
* 1.1.0 - April 24th, 2012
|
34
37
|
* Deprecate the ActiveRecord::Acts::Tree module in favor of ActsAsTree
|
35
38
|
* 1.0.1 - April 18th, 2012
|
data/lib/acts_as_tree/version.rb
CHANGED
data/lib/acts_as_tree.rb
CHANGED
@@ -3,22 +3,9 @@ require 'acts_as_tree/version'
|
|
3
3
|
module ActsAsTree
|
4
4
|
|
5
5
|
if defined? Rails::Railtie
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
9
|
-
ActiveSupport.on_load :active_record do
|
10
|
-
ActsAsTree::Railtie.insert
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Railtie
|
17
|
-
def self.insert
|
18
|
-
if defined?(ActiveRecord)
|
19
|
-
ActiveRecord::Base.send(:include, ActsAsTree)
|
20
|
-
end
|
21
|
-
end
|
6
|
+
require 'acts_as_tree/railtie'
|
7
|
+
elsif defined? Rails::Initializer
|
8
|
+
raise "acts_as_tree 1.0 is not compatible with Rails 2.3 or older"
|
22
9
|
end
|
23
10
|
|
24
11
|
def self.included(base)
|
@@ -31,7 +18,7 @@ module ActsAsTree
|
|
31
18
|
# +parent_id+.
|
32
19
|
#
|
33
20
|
# class Category < ActiveRecord::Base
|
34
|
-
# include
|
21
|
+
# include ActsAsTree
|
35
22
|
#
|
36
23
|
# acts_as_tree :order => "name"
|
37
24
|
# end
|
@@ -95,23 +82,19 @@ module ActsAsTree
|
|
95
82
|
inverse_of: :parent
|
96
83
|
|
97
84
|
class_eval <<-EOV
|
98
|
-
|
85
|
+
include ActsAsTree::InstanceMethods
|
99
86
|
|
100
|
-
|
87
|
+
after_update :update_parents_counter_cache
|
101
88
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
order: order_option)
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.root
|
110
|
-
order_option = %Q{#{configuration.fetch :order, "nil"}}
|
89
|
+
def self.roots
|
90
|
+
order_option = %Q{#{configuration.fetch :order, "nil"}}
|
91
|
+
where(:#{configuration[:foreign_key]} => nil).order(order_option)
|
92
|
+
end
|
111
93
|
|
112
|
-
|
113
|
-
|
114
|
-
|
94
|
+
def self.root
|
95
|
+
order_option = %Q{#{configuration.fetch :order, "nil"}}
|
96
|
+
self.roots.first
|
97
|
+
end
|
115
98
|
EOV
|
116
99
|
end
|
117
100
|
end
|
@@ -154,6 +137,13 @@ module ActsAsTree
|
|
154
137
|
[self] + self.children
|
155
138
|
end
|
156
139
|
|
140
|
+
# Returns ancestors and current node itself.
|
141
|
+
#
|
142
|
+
# subchild1.self_and_ancestors # => [subchild1, child1, root]
|
143
|
+
def self_and_ancestors
|
144
|
+
[self] + self.ancestors
|
145
|
+
end
|
146
|
+
|
157
147
|
private
|
158
148
|
|
159
149
|
def update_parents_counter_cache
|
data/test/acts_as_tree_test.rb
CHANGED
@@ -161,6 +161,11 @@ class TreeTest < Test::Unit::TestCase
|
|
161
161
|
assert_equal [@root2], @root2.self_and_children
|
162
162
|
end
|
163
163
|
|
164
|
+
def test_self_and_ancestors
|
165
|
+
assert_equal [@child1_child, @root_child1, @root1], @child1_child.self_and_ancestors
|
166
|
+
assert_equal [@root2], @root2.self_and_ancestors
|
167
|
+
end
|
168
|
+
|
164
169
|
def test_nullify
|
165
170
|
root4 = TreeMixinNullify.create!
|
166
171
|
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.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,11 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2012-
|
15
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
19
|
-
requirement:
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
22
|
- - ! '>='
|
@@ -24,10 +24,15 @@ dependencies:
|
|
24
24
|
version: 3.0.0
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
28
33
|
- !ruby/object:Gem::Dependency
|
29
34
|
name: sqlite3
|
30
|
-
requirement:
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
31
36
|
none: false
|
32
37
|
requirements:
|
33
38
|
- - ! '>='
|
@@ -35,10 +40,15 @@ dependencies:
|
|
35
40
|
version: '0'
|
36
41
|
type: :development
|
37
42
|
prerelease: false
|
38
|
-
version_requirements:
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
39
49
|
- !ruby/object:Gem::Dependency
|
40
50
|
name: rdoc
|
41
|
-
requirement:
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
42
52
|
none: false
|
43
53
|
requirements:
|
44
54
|
- - ! '>='
|
@@ -46,7 +56,12 @@ dependencies:
|
|
46
56
|
version: '0'
|
47
57
|
type: :development
|
48
58
|
prerelease: false
|
49
|
-
version_requirements:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
50
65
|
description: A gem that adds simple support for organizing ActiveRecord models into
|
51
66
|
parent–children relationships.
|
52
67
|
email:
|
@@ -65,6 +80,7 @@ files:
|
|
65
80
|
- acts_as_tree.gemspec
|
66
81
|
- lib/acts_as_tree.rb
|
67
82
|
- lib/acts_as_tree/active_record/acts/tree.rb
|
83
|
+
- lib/acts_as_tree/railtie.rb
|
68
84
|
- lib/acts_as_tree/version.rb
|
69
85
|
- test/acts_as_tree_test.rb
|
70
86
|
homepage: https://github.com/amerine/acts_as_tree
|
@@ -88,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
104
|
version: '0'
|
89
105
|
requirements: []
|
90
106
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.23
|
92
108
|
signing_key:
|
93
109
|
specification_version: 3
|
94
110
|
summary: Provides a simple tree behaviour to active_record models.
|