mongoid-tree 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Gemfile.lock +18 -17
  2. data/README.rdoc +21 -3
  3. data/lib/mongoid/tree.rb +5 -10
  4. metadata +4 -4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-tree (0.3.0)
4
+ mongoid-tree (0.3.1)
5
5
  mongoid (>= 2.0.0.beta.17)
6
6
 
7
7
  GEM
@@ -12,9 +12,9 @@ GEM
12
12
  builder (~> 2.1.2)
13
13
  i18n (~> 0.4.1)
14
14
  activesupport (3.0.0)
15
- autotest (4.3.2)
16
- bson (1.0.4)
17
- bson_ext (1.0.7)
15
+ autotest (4.4.1)
16
+ bson (1.1)
17
+ bson_ext (1.1)
18
18
  builder (2.1.2)
19
19
  diff-lcs (1.1.2)
20
20
  haml (2.2.24)
@@ -23,24 +23,25 @@ GEM
23
23
  rake (~> 0.8.2)
24
24
  rdoc (~> 2.3.0)
25
25
  i18n (0.4.1)
26
- mongo (1.0.7)
27
- bson (>= 1.0.4)
28
- mongoid (2.0.0.beta.17)
29
- activemodel (~> 3.0.0)
30
- bson (= 1.0.4)
31
- mongo (= 1.0.7)
26
+ mongo (1.0.9)
27
+ bson (>= 1.0.5)
28
+ mongoid (2.0.0.beta.19)
29
+ activemodel (~> 3.0)
30
+ mongo (= 1.0.9)
32
31
  tzinfo (~> 0.3.22)
33
32
  will_paginate (~> 3.0.pre)
34
33
  rake (0.8.7)
35
34
  rdoc (2.3.0)
36
- rspec (2.0.0.beta.20)
37
- rspec-core (= 2.0.0.beta.20)
38
- rspec-expectations (= 2.0.0.beta.20)
39
- rspec-mocks (= 2.0.0.beta.20)
40
- rspec-core (2.0.0.beta.20)
41
- rspec-expectations (2.0.0.beta.20)
35
+ rspec (2.0.0.rc)
36
+ rspec-core (= 2.0.0.rc)
37
+ rspec-expectations (= 2.0.0.rc)
38
+ rspec-mocks (= 2.0.0.rc)
39
+ rspec-core (2.0.0.rc)
40
+ rspec-expectations (2.0.0.rc)
42
41
  diff-lcs (>= 1.1.2)
43
- rspec-mocks (2.0.0.beta.20)
42
+ rspec-mocks (2.0.0.rc)
43
+ rspec-core (= 2.0.0.rc)
44
+ rspec-expectations (= 2.0.0.rc)
44
45
  tzinfo (0.3.23)
45
46
  will_paginate (3.0.pre2)
46
47
 
data/README.rdoc CHANGED
@@ -10,13 +10,13 @@ A tree structure for Mongoid documents using the materialized path pattern
10
10
 
11
11
  To install mongoid_tree, simply add it to your Gemfile:
12
12
 
13
- gem 'mongoid-tree'
13
+ gem 'mongoid-tree', :require => 'mongoid/tree'
14
14
 
15
15
  In order to get the latest development version of mongoid-tree:
16
16
 
17
- gem 'mongoid-tree', :git => 'git://github.com/benedikt/mongoid-tree'
17
+ gem 'mongoid-tree', :git => 'git://github.com/benedikt/mongoid-tree', :require => 'mongoid/tree'
18
18
 
19
- You might want to add the <tt>:require => 'mongoid/tree'</tt> option as well and finally run
19
+ You might want to remove the <tt>:require => 'mongoid/tree'</tt> option and explicitly <tt>require 'mongoid/tree'</tt> where needed and finally run
20
20
 
21
21
  bundle install
22
22
 
@@ -92,6 +92,24 @@ Example:
92
92
 
93
93
  There are two callbacks that are called before and after the rearranging process. This enables you to do additional computations after the documents position in the tree is updated. See Mongoid::Tree for details.
94
94
 
95
+ Example:
96
+
97
+ class Page
98
+ include Mongoid::Document
99
+ include Mongoid::Tree
100
+
101
+ after_rearrange :rebuild_path
102
+
103
+ field :slug
104
+ field :path
105
+
106
+ private
107
+
108
+ def rebuild_path
109
+ self.path = self.ancestors_and_self.collect(&:slug).join('/')
110
+ end
111
+ end
112
+
95
113
  == Known issues
96
114
 
97
115
  See http://github.com/benedikt/mongoid-tree/issues
data/lib/mongoid/tree.rb CHANGED
@@ -98,6 +98,8 @@ module Mongoid # :nodoc:
98
98
  validate :position_in_tree
99
99
 
100
100
  define_model_callbacks :rearrange, :only => [:before, :after]
101
+
102
+ class_eval "def base_class; #{self.name}; end"
101
103
  end
102
104
 
103
105
  ##
@@ -260,32 +262,25 @@ module Mongoid # :nodoc:
260
262
  end
261
263
 
262
264
  ##
263
- # Moves all children to this documents parent
265
+ # Moves all children to this document's parent
264
266
  def move_children_to_parent
265
267
  children.each { |c| c.update_attributes(:parent_id => self.parent_id) }
266
268
  end
267
269
 
268
270
  ##
269
- # Deletes all children using the database (doesn't invoke callbacks)
271
+ # Deletes all descendants using the database (doesn't invoke callbacks)
270
272
  def delete_descendants
271
273
  base_class.delete_all(:conditions => { :parent_ids => self.id })
272
274
  end
273
275
 
274
276
  ##
275
- # Destroys all children by calling their (does invoke callbacks)
277
+ # Destroys all children by calling their #destroy method (does invoke callbacks)
276
278
  def destroy_children
277
279
  children.destroy_all
278
280
  end
279
281
 
280
282
  private
281
283
 
282
- def base_class
283
- @base_class ||= begin
284
- parent_classes = self.class.ancestors.select{|c| !c.name[/^Mongoid|ActiveModel|ActiveSupport/i]}
285
- parent_classes[parent_classes.index(Object) - 1]
286
- end
287
- end
288
-
289
284
  def rearrange
290
285
  if self.parent_id
291
286
  self.parent_ids = base_class.find(self.parent_id).parent_ids + [self.parent_id]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-tree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benedikt Deicke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-31 00:00:00 +02:00
18
+ date: 2010-10-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency