mongoid-tree 2.1.1 → 2.3.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
  SHA256:
3
- metadata.gz: 95f09f86db1baaf40ff2ccc51870dac22ce57cc4d46e6ba432cfca2d8da1ee72
4
- data.tar.gz: 7363956d97733f02f4d2b06058112d8e0c4a32da4ac238902886ca1308d7782a
3
+ metadata.gz: f6ab2c06f002db333cabe89dae42565fb90fdfc44fa55c8f5253729fe86845b9
4
+ data.tar.gz: dd89cbd4ec988c2a00b980d9981a7684358a16ba19f084416009be2434631726
5
5
  SHA512:
6
- metadata.gz: 45489275101e16064a9ee2e95c60ee9127721c623fe9a23b948ef78901517b8e3c2aac7b85972bacb824e7340312771e8f2b7b2abbffc9e0aff320e2e6c27e51
7
- data.tar.gz: 37aa5b0f41b6a2fbfbc04caf8ff684c86f1d42fefdd244fc2f82d72f31c6ace7718d1b3727141efdddfe213bab6124945e2eedb7923c10e1474d4f4029ff514c
6
+ metadata.gz: 64e780500872ad2a34b5e5d5ef987b64b9d0e68d6afe6e567dbcc66e063ed63c46b95f22ed6d145a3fda60ada59b208c344fabf8a17ebae933de0bef69bd73e2
7
+ data.tar.gz: 86954c1360bfea51cd68ade0beec3ebe959a1878acc23a2a07795c4612b503041dc5ec507850259c9ad0c8ab65c9612183a606b6549aadcea98191e1c5377829
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ gemspec
4
4
 
5
5
  case version = ENV['MONGOID_VERSION'] || '~> 7.0'
6
6
  when 'HEAD' then gem 'mongoid', github: 'mongodb/mongoid'
7
+ when /9/ then gem 'mongoid', '~> 9.0'
8
+ when /8/ then gem 'mongoid', '~> 8.0'
7
9
  when /7/ then gem 'mongoid', '~> 7.0'
8
10
  when /6/ then gem 'mongoid', '~> 6.0'
9
11
  when /5/ then gem 'mongoid', '~> 5.0'
@@ -16,7 +18,3 @@ unless ENV['CI']
16
18
  gem 'ruby_gntp', '>= 0.3.4'
17
19
  gem 'rb-fsevent' if RUBY_PLATFORM =~ /darwin/
18
20
  end
19
-
20
- platforms :rbx do
21
- gem 'rubysl-rake', '~> 2.0'
22
- end
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # mongoid-tree [![Build Status](https://secure.travis-ci.org/benedikt/mongoid-tree.svg?branch=master)](http://travis-ci.org/benedikt/mongoid-tree) [![Dependency Status](https://gemnasium.com/benedikt/mongoid-tree.svg)](http://gemnasium.com/benedikt/mongoid-tree)
1
+ # mongoid-tree [![Build Status](https://github.com/benedikt/mongoid-tree/workflows/Tests/badge.svg)](https://github.com/benedikt/mongoid-tree)
2
2
 
3
3
  A tree structure for Mongoid documents using the materialized path pattern
4
4
 
5
5
  ## Requirements
6
6
 
7
- * mongoid (>= 4.0, < 7.0)
7
+ * mongoid (>= 4.0, < 10.0)
8
8
 
9
9
  For a mongoid 3.x compatible version, please use mongoid-tree 1.0.x,
10
10
  for a mongoid 2.x compatible version, please use mongoid-tree 0.7.x.
@@ -14,13 +14,13 @@ for a mongoid 2.x compatible version, please use mongoid-tree 0.7.x.
14
14
 
15
15
  To install mongoid_tree, simply add it to your Gemfile:
16
16
 
17
- gem 'mongoid-tree', :require => 'mongoid/tree'
17
+ gem 'mongoid-tree', require: 'mongoid/tree'
18
18
 
19
19
  In order to get the latest development version of mongoid-tree:
20
20
 
21
- gem 'mongoid-tree', :git => 'git://github.com/benedikt/mongoid-tree'
21
+ gem 'mongoid-tree', git: 'git://github.com/benedikt/mongoid-tree', branch: :main
22
22
 
23
- You might want to add `:require => nil` option and explicitly `require 'mongoid/tree'` where needed and finally run
23
+ You might want to add `require: nil` option and explicitly `require 'mongoid/tree'` where needed and finally run
24
24
 
25
25
  bundle install
26
26
 
@@ -30,7 +30,7 @@ To fix issues with the ordering of ancestors, mongoid-tree 2.0 introduces a new
30
30
 
31
31
  ## Usage
32
32
 
33
- Read the API documentation at http://benedikt.github.com/mongoid-tree and take a look at the `Mongoid::Tree` module
33
+ Read the API documentation at https://www.rubydoc.info/github/benedikt/mongoid-tree and take a look at the `Mongoid::Tree` module
34
34
 
35
35
  ```ruby
36
36
  class Node
@@ -189,7 +189,7 @@ end
189
189
 
190
190
  ## Build Status
191
191
 
192
- mongoid-tree is on [Travis CI](http://travis-ci.org/benedikt/mongoid-tree) running the specs on Ruby Head, Ruby 1.9.3, JRuby (1.9 mode), and Rubinius (1.9 mode).
192
+ mongoid-tree is on [GitHub Actions](https://github.com/benedikt/mongoid-tree/actions) running the specs on Ruby 3.1-3.3 and Mongoid 4.x-9.x.
193
193
 
194
194
  ## Known issues
195
195
 
@@ -206,14 +206,6 @@ See [https://github.com/benedikt/mongoid-tree](https://github.com/benedikt/mongo
206
206
  See a list of all contributors at [https://github.com/benedikt/mongoid-tree/contributors](https://github.com/benedikt/mongoid-tree/contributors). Thanks a lot everyone!
207
207
 
208
208
 
209
- ## Support
210
-
211
- If you like mongoid-tree and want to support the development, I would appreciate a small donation:
212
-
213
- [![Pledgie](http://www.pledgie.com/campaigns/12137.png?skin_name=chrome)](http://www.pledgie.com/campaigns/12137)
214
-
215
- [![Flattr](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=benediktdeicke&url=https://github.com/benedikt/mongoid-tree&title=mongoid-tree&language=&tags=github&category=software)
216
-
217
209
  ## Copyright
218
210
 
219
- Copyright (c) 2010-2013 Benedikt Deicke. See LICENSE for details.
211
+ Copyright (c) 2010-2024 Benedikt Deicke. See LICENSE for details.
@@ -0,0 +1,26 @@
1
+ module Mongoid
2
+ module Tree
3
+ ##
4
+ # = Mongoid::Tree::CounterCaching
5
+ #
6
+ # Mongoid::Tree doesn't use a counter cache for the children by default.
7
+ # To enable counter caching for each node's children, include
8
+ # both Mongoid::Tree and Mongoid::Tree::CounterCaching into your document.
9
+ module CounterCaching
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ field :children_count, :type => Integer, :default => 0
14
+
15
+ metadata = relations['parent']
16
+ metadata.options[:counter_cache] = true
17
+
18
+ if respond_to?(:add_counter_cache_callbacks)
19
+ add_counter_cache_callbacks(metadata)
20
+ else
21
+ metadata.send(:define_counter_cache_callbacks!)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/mongoid/tree.rb CHANGED
@@ -83,6 +83,7 @@ module Mongoid
83
83
 
84
84
  autoload :Ordering, 'mongoid/tree/ordering'
85
85
  autoload :Traversal, 'mongoid/tree/traversal'
86
+ autoload :CounterCaching, 'mongoid/tree/counter_caching'
86
87
 
87
88
  included do
88
89
  has_many :children, :class_name => self.name, :foreign_key => :parent_id, :inverse_of => :parent, :validate => false
@@ -431,7 +432,7 @@ module Mongoid
431
432
  # @private
432
433
  # @return [undefined]
433
434
  def rearrange
434
- if self.parent_id
435
+ if parent.present?
435
436
  self.parent_ids = parent.parent_ids + [self.parent_id]
436
437
  else
437
438
  self.parent_ids = []
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::Tree::CounterCaching do
4
+
5
+ subject { CounterCachedNode }
6
+
7
+ before do
8
+ setup_tree <<-ENDTREE
9
+ node1:
10
+ - node2:
11
+ - node3
12
+ - node4:
13
+ - node5
14
+ - node6
15
+ - node7
16
+ ENDTREE
17
+ end
18
+
19
+ context 'when a child gets created' do
20
+ it 'should calculate the counter cache' do
21
+ expect(node(:node1).children_count).to eq(3)
22
+ end
23
+ end
24
+
25
+ context 'when a child gets destroyed' do
26
+ it 'should update the counter cache' do
27
+ node(:node4).destroy
28
+ expect(node(:node1).children_count).to eq(2)
29
+ end
30
+ end
31
+
32
+ context 'when a child gets moved' do
33
+ it 'should update the counter cache' do
34
+ node(:node6).update(parent: node(:node1))
35
+ expect(node(:node4).children_count).to eq(1)
36
+ expect(node(:node1).children_count).to eq(4)
37
+ end
38
+ end
39
+ end
@@ -328,9 +328,9 @@ describe Mongoid::Tree do
328
328
  - subsubchild
329
329
  ENDTREE
330
330
 
331
- filtered_ancestors = node(:subsubchild).ancestors.or(
332
- { :name => 'child' },
333
- { :name => 'subchild' }
331
+ filtered_ancestors = node(:subsubchild).ancestors.any_of(
332
+ { :name => 'child' },
333
+ { :name => 'subchild' }
334
334
  )
335
335
 
336
336
  expect(filtered_ancestors.to_a).to eq([node(:child), node(:subchild)])
@@ -29,4 +29,8 @@ end
29
29
 
30
30
  class EmbeddedDocument
31
31
  include Mongoid::Document
32
- end
32
+ end
33
+
34
+ class CounterCachedNode < Node
35
+ include Mongoid::Tree::CounterCaching
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benedikt Deicke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2024-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8'
22
+ version: '10'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8'
32
+ version: '10'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: mongoid-compatibility
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -76,16 +76,16 @@ dependencies:
76
76
  name: yard
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '0.8'
81
+ version: 0.9.20
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: '0.8'
88
+ version: 0.9.20
89
89
  description: A tree structure for Mongoid documents using the materialized path pattern
90
90
  email:
91
91
  - benedikt@synatic.net
@@ -93,14 +93,15 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
- - ".rspec"
97
96
  - Gemfile
98
97
  - LICENSE
99
98
  - README.md
100
99
  - Rakefile
101
100
  - lib/mongoid/tree.rb
101
+ - lib/mongoid/tree/counter_caching.rb
102
102
  - lib/mongoid/tree/ordering.rb
103
103
  - lib/mongoid/tree/traversal.rb
104
+ - spec/mongoid/tree/counter_caching_spec.rb
104
105
  - spec/mongoid/tree/ordering_spec.rb
105
106
  - spec/mongoid/tree/traversal_spec.rb
106
107
  - spec/mongoid/tree_spec.rb
@@ -112,7 +113,7 @@ homepage: https://github.com/benedikt/mongoid-tree
112
113
  licenses:
113
114
  - MIT
114
115
  metadata: {}
115
- post_install_message:
116
+ post_install_message:
116
117
  rdoc_options: []
117
118
  require_paths:
118
119
  - lib
@@ -127,9 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.7.6
132
- signing_key:
131
+ rubygems_version: 3.5.3
132
+ signing_key:
133
133
  specification_version: 4
134
134
  summary: A tree structure for Mongoid documents
135
135
  test_files: []
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format documentation