acts_as_tree 1.1.0 → 1.2.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.
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
@@ -0,0 +1,11 @@
1
+ module ActsAsTree
2
+
3
+ class Railtie < Rails::Railtie
4
+ initializer 'acts_as_tree.insert_into_active_record' do
5
+ ActiveSupport.on_load :active_record do
6
+ ActiveRecord::Base.send(:include, ActsAsTree)
7
+ end
8
+ end
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ActsAsTree
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
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 'rails'
7
- class Railtie < Rails::Railtie
8
- initializer 'acts_as_tree.insert_into_active_record' do
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 ActiveRecord::Acts:Tree
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
- include ActsAsTree::InstanceMethods
85
+ include ActsAsTree::InstanceMethods
99
86
 
100
- after_update :update_parents_counter_cache
87
+ after_update :update_parents_counter_cache
101
88
 
102
- def self.roots
103
- order_option = %Q{#{configuration.fetch :order, "nil"}}
104
-
105
- find(:all, conditions: "#{configuration[:foreign_key]} IS NULL",
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
- find(:first, conditions: "#{configuration[:foreign_key]} IS NULL",
113
- order: order_option)
114
- end
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
@@ -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.1.0
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-04-25 00:00:00.000000000 Z
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: &70112110455280 !ruby/object:Gem::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: *70112110455280
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: &70112110454840 !ruby/object:Gem::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: *70112110454840
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: &70112110454380 !ruby/object:Gem::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: *70112110454380
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.11
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.