closure_tree 2.0.0.beta1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,13 +10,13 @@ for a description of different tree storage algorithms.
10
10
 
11
11
  ## Setup
12
12
 
13
- Note that closure_tree is being developed for Rails 3.1.0.rc1
13
+ Note that closure_tree is being developed for Rails 3.1.x
14
14
 
15
15
  1. Add this to your Gemfile: ```gem 'closure_tree'```
16
16
 
17
17
  2. Run ```bundle install```
18
18
 
19
- 3. Add ```acts_as_tree``` to your hierarchical model(s) (see the <a href="#options">available options</a>).
19
+ 3. Add ```acts_as_tree``` to your hierarchical model(s) (see the <em>Available options</em> section below for details).
20
20
 
21
21
  4. Add a migration to add a ```parent_id``` column to the model you want to act_as_tree.
22
22
 
@@ -67,23 +67,29 @@ Note that closure_tree is being developed for Rails 3.1.0.rc1
67
67
  Create a root node:
68
68
 
69
69
  ```ruby
70
- grandparent = Tag.create!(:name => 'Grandparent')
70
+ grandparent = Tag.create(:name => 'Grandparent')
71
71
  ```
72
72
 
73
- There are two equivalent ways to add children. Either use the ```add_child``` method:
73
+ Child nodes are created by appending to the children collection:
74
74
 
75
75
  ```ruby
76
- parent = Tag.create!(:name => 'Parent')
77
- grandparent.add_child parent
76
+ child = parent.children.create(:name => 'Child')
78
77
  ```
79
78
 
80
- Or append to the ```children``` collection:
79
+ You can also append to the children collection:
81
80
 
82
81
  ```ruby
83
- child = Tag.create!(:name => 'Child')
82
+ child = Tag.create(:name => 'Child')
84
83
  parent.children << child
85
84
  ```
86
-
85
+
86
+ Or call the "add_child" method:
87
+
88
+ ```ruby
89
+ parent = Tag.create(:name => 'Parent')
90
+ grandparent.add_child parent
91
+ ```
92
+
87
93
  Then:
88
94
 
89
95
  ```ruby
@@ -99,7 +105,7 @@ Then:
99
105
  We can do all the node creation and add_child calls from the prior section with one method call:
100
106
 
101
107
  ```ruby
102
- child = Tag.find_or_create_by_path "grandparent", "parent", "child"
108
+ child = Tag.find_or_create_by_path("grandparent", "parent", "child")
103
109
  ```
104
110
 
105
111
  You can ```find``` as well as ```find_or_create``` by "ancestry paths". Ancestry paths may be built using any column in your model. The default column is ```name```, which can be changed with the :name_column option provided to ```acts_as_tree```.
@@ -111,13 +117,13 @@ Note that the other columns will be null if nodes are created, other than auto-g
111
117
 
112
118
  When you include ```acts_as_tree``` in your model, you can provide a hash to override the following defaults:
113
119
 
114
- * ```:parent_column_name``` to override the column name of the parent foreign key in the model's table
120
+ * ```:parent_column_name``` to override the column name of the parent foreign key in the model's table. This defaults to "parent_id".
115
121
  * ```:hierarchy_table_name``` to override the hierarchy table name. This defaults to the singular name of the model + "_hierarchies".
116
- * ```:name_column``` used by #```find_or_create_by_path```, #```find_by_path```, and ```ancestry_path``` instance methods. This is primarily useful if the model only has one required field (like a "tag").
117
122
  * ```:dependent``` determines what happens when a node is destroyed. Defaults to ```nil```.
118
- * ```nil``` will simply set the parent column to null. Each child node will be considered a "root" node
123
+ * ```:nullify``` will simply set the parent column to null. Each child node will be considered a "root" node. This is the default.
119
124
  * ```:delete_all``` will delete all descendant nodes (which circumvents the destroy hooks)
120
125
  * ```:destroy``` will destroy all descendant nodes (which runs the destroy hooks on each child node)
126
+ * ```:name_column``` used by #```find_or_create_by_path```, #```find_by_path```, and ```ancestry_path``` instance methods. This is primarily useful if the model only has one required field (like a "tag").
121
127
 
122
128
  ## Accessing Data
123
129
 
@@ -143,8 +149,7 @@ When you include ```acts_as_tree``` in your model, you can provide a hash to ove
143
149
  * ``` tag.self_and_siblings``` returns an array of brothers and sisters (all at that level), including self.
144
150
  * ``` tag.descendants``` returns an array of all children, childrens' children, etc., excluding self.
145
151
  * ``` tag.self_and_descendants``` returns an array of all children, childrens' children, etc., including self.
146
- * ``` tag.reparent``` lets you move a node (and all it's children) to a new parent.
147
- * ``` tag.destroy``` will destroy a node as well as possibly all of its children. See the ```:dependent``` option passed to ```acts_as_tree```.
152
+ * ``` tag.destroy``` will destroy a node and do <em>something</em> to its children, which is determined by the ```:dependent``` option passed to ```acts_as_tree```.
148
153
 
149
154
  ## Changelog
150
155
 
@@ -152,7 +157,6 @@ When you include ```acts_as_tree``` in your model, you can provide a hash to ove
152
157
 
153
158
  * Had to increment the major version, as rebuild! will need to be called by prior consumers to support the new ```leaves``` class and instance methods.
154
159
  * Tag deletion is supported now along with ```:dependent => :destroy``` and ```:dependent => :delete_all```
155
- * Added new instance method ```reparent```
156
160
  * Switched from default rails plugin directory structure to rspec
157
161
 
158
162
  ## Thanks to
data/Rakefile CHANGED
@@ -15,3 +15,6 @@ require "rspec/core/rake_task"
15
15
  RSpec::Core::RakeTask.new(:spec)
16
16
 
17
17
  task :default => :spec
18
+
19
+ # Run the specs using all the different database engines:
20
+ # for DB in sqlite3 mysql postgresql ; do rake ; done
@@ -242,22 +242,6 @@ module ClosureTree
242
242
  root = roots.send("find_or_create_by_#{name_column}", path.shift)
243
243
  root.find_or_create_by_path(*path)
244
244
  end
245
-
246
- # From https://github.com/collectiveidea/awesome_nested_set:
247
- def in_tenacious_transaction(&block)
248
- retry_count = 0
249
- begin
250
- transaction(&block)
251
- rescue ActiveRecord::StatementInvalid => error
252
- raise unless connection.open_transactions.zero?
253
- raise unless error.message =~ /Deadlock found when trying to get lock|Lock wait timeout exceeded/
254
- raise unless retry_count < 10
255
- retry_count += 1
256
- logger.info "Deadlock detected on retry #{retry_count}, restarting transaction"
257
- sleep(rand(retry_count)*0.2) # Aloha protocol
258
- retry
259
- end
260
- end
261
245
  end
262
246
  end
263
247
 
@@ -1,3 +1,3 @@
1
1
  module ClosureTree
2
- VERSION = "2.0.0.beta1" unless defined?(::ClosureTree::VERSION)
2
+ VERSION = "2.0.0" unless defined?(::ClosureTree::VERSION)
3
3
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closure_tree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196449
5
- prerelease: 6
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 0
10
- - beta
11
- - 1
12
- version: 2.0.0.beta1
10
+ version: 2.0.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Matthew McEachen
@@ -17,7 +15,7 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2011-10-27 00:00:00 Z
18
+ date: 2011-11-24 00:00:00 Z
21
19
  dependencies:
22
20
  - !ruby/object:Gem::Dependency
23
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -79,14 +77,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
77
  required_rubygems_version: !ruby/object:Gem::Requirement
80
78
  none: false
81
79
  requirements:
82
- - - ">"
80
+ - - ">="
83
81
  - !ruby/object:Gem::Version
84
- hash: 25
82
+ hash: 3
85
83
  segments:
86
- - 1
87
- - 3
88
- - 1
89
- version: 1.3.1
84
+ - 0
85
+ version: "0"
90
86
  requirements: []
91
87
 
92
88
  rubyforge_project: