mongoid-tree 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fdc505bb8df0d134efa3f5f4d3afca14603a44cd
4
- data.tar.gz: 2615195789c03a83ffe7cce55218ac0c9e8ff5e3
2
+ SHA256:
3
+ metadata.gz: 2d75be10c74b80e4233e3865d42bdca651a741ec3c535b41eee3da042297a195
4
+ data.tar.gz: 45b2f88c1d46bcd9819b66701d4d16eaef3874a6e92d09fbb4e5cc6bcd06e767
5
5
  SHA512:
6
- metadata.gz: 8cd3e9933fa16933ba6044826fe5bd935b4d2f93f4580c5bf63ebf2d6480a0941dedeb48b3b06118b2827e87564020760d4b6421fcb87b760846d69296b3078b
7
- data.tar.gz: 4a3609b0eb8e493952f3cf3bc222fc217a14f2a06cee2dae34f128fec7f4438a8f9ab30370cea2fbf6f146d2ff98c607e1b0afc15b70f32950aeef9ad7e27eaa
6
+ metadata.gz: 697aab3571146827d8a2ec7987890c185e9685b821ff8fcd3c46487d3512c962322990a36c9977b5bde7cc5ae332d153e42a2b920c1904c09efbf47118c4b2d9
7
+ data.tar.gz: 63426c0b41fbbc0a8559dfeda7f3e5a158b230084fff852dcd984a3919cf22d230d27df0c3b2cb4f2c934e15356859430701fbad00bcfb0d0d7e255e0e494df5
data/Gemfile CHANGED
@@ -2,10 +2,18 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'guard-rspec', '>= 0.6.0'
6
- gem 'ruby_gntp', '>= 0.3.4'
7
- gem 'rb-fsevent' if RUBY_PLATFORM =~ /darwin/
5
+ case version = ENV['MONGOID_VERSION'] || '~> 7.0'
6
+ when 'HEAD' then gem 'mongoid', github: 'mongodb/mongoid'
7
+ when /8/ then gem 'mongoid', '~> 8.0'
8
+ when /7/ then gem 'mongoid', '~> 7.0'
9
+ when /6/ then gem 'mongoid', '~> 6.0'
10
+ when /5/ then gem 'mongoid', '~> 5.0'
11
+ when /4/ then gem 'mongoid', '~> 4.0'
12
+ else gem 'mongoid', version
13
+ end
8
14
 
9
- platforms :rbx do
10
- gem 'rubysl-rake', '~> 2.0'
15
+ unless ENV['CI']
16
+ gem 'guard-rspec', '>= 0.6.0'
17
+ gem 'ruby_gntp', '>= 0.3.4'
18
+ gem 'rb-fsevent' if RUBY_PLATFORM =~ /darwin/
11
19
  end
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # mongoid-tree [![Build Status](https://secure.travis-ci.org/benedikt/mongoid-tree.png?branch=master)](http://travis-ci.org/benedikt/mongoid-tree) [![Dependency Status](https://gemnasium.com/benedikt/mongoid-tree.png)](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, < 9.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 2.7-3.2 and Mongoid 4.x-8.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-2023 Benedikt Deicke. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,25 +1,14 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rspec/core/rake_task'
2
3
  require 'yard'
3
4
 
4
- spec = Gem::Specification.load("mongoid-tree.gemspec")
5
-
6
5
  RSpec::Core::RakeTask.new(:spec)
7
6
 
8
7
  task :default => :spec
9
8
 
10
9
  YARD::Rake::YardocTask.new(:doc)
11
10
 
12
- desc "Build the .gem file"
13
- task :build do
14
- system "gem build #{spec.name}.gemspec"
15
- end
16
-
17
- desc "Push the .gem file to rubygems.org"
18
- task :release => :build do
19
- system "gem push #{spec.name}-#{spec.version}.gem"
20
- end
21
-
22
11
  desc "Open an irb session"
23
12
  task :console do
24
13
  sh "irb -rubygems -I lib -r ./spec/spec_helper.rb"
25
- end
14
+ end
@@ -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
@@ -15,7 +15,7 @@ describe Mongoid::Tree::Traversal do
15
15
  end
16
16
 
17
17
  it "should complain about unsupported traversal methods" do
18
- expect { subject.traverse('non_existing') {} }.to raise_error
18
+ expect { subject.traverse('non_existing') {} }.to raise_error NoMethodError
19
19
  end
20
20
 
21
21
  it "should default to depth_first traversal" do
@@ -7,7 +7,11 @@ describe Mongoid::Tree do
7
7
  it "should reference many children as inverse of parent with index" do
8
8
  a = Node.reflect_on_association(:children)
9
9
  expect(a).to be
10
- expect(a.macro).to eq(:has_many)
10
+ if Mongoid::Compatibility::Version.mongoid7?
11
+ expect(a).to be_kind_of(Mongoid::Association::Referenced::HasMany)
12
+ else
13
+ expect(a.macro).to eq(:has_many)
14
+ end
11
15
  expect(a.class_name).to eq('Node')
12
16
  expect(a.foreign_key).to eq('parent_id')
13
17
  expect(Node.index_specification(:parent_id => 1)).to be
@@ -16,7 +20,11 @@ describe Mongoid::Tree do
16
20
  it "should be referenced in one parent as inverse of children" do
17
21
  a = Node.reflect_on_association(:parent)
18
22
  expect(a).to be
19
- expect(a.macro).to eq(:belongs_to)
23
+ if Mongoid::Compatibility::Version.mongoid7?
24
+ expect(a).to be_kind_of(Mongoid::Association::Referenced::BelongsTo)
25
+ else
26
+ expect(a.macro).to eq(:belongs_to)
27
+ end
20
28
  expect(a.class_name).to eq('Node')
21
29
  expect(a.inverse_of).to eq(:children)
22
30
  end
@@ -320,9 +328,9 @@ describe Mongoid::Tree do
320
328
  - subsubchild
321
329
  ENDTREE
322
330
 
323
- filtered_ancestors = node(:subsubchild).ancestors.or(
324
- { :name => 'child' },
325
- { :name => 'subchild' }
331
+ filtered_ancestors = node(:subsubchild).ancestors.any_of(
332
+ { :name => 'child' },
333
+ { :name => 'subchild' }
326
334
  )
327
335
 
328
336
  expect(filtered_ancestors.to_a).to eq([node(:child), node(:subchild)])
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'bundler/setup'
3
3
 
4
4
  require 'mongoid'
5
5
  require 'mongoid/tree'
6
+ require 'mongoid-compatibility'
6
7
 
7
8
  require 'rspec'
8
9
 
@@ -0,0 +1,9 @@
1
+ FileUtils.mkdir_p File.expand_path('../../../log', __FILE__)
2
+
3
+ logger = Logger.new('log/mongoid.log')
4
+
5
+ if Mongoid::Compatibility::Version.mongoid5_or_newer?
6
+ Mongoid.logger = Mongo::Logger.logger = logger
7
+ else
8
+ Mongoid.logger = logger
9
+ end
@@ -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,35 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.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: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2023-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: '7.0'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '9'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
27
30
  - - "<"
28
31
  - !ruby/object:Gem::Version
29
- version: '7.0'
32
+ version: '9'
33
+ - !ruby/object:Gem::Dependency
34
+ name: mongoid-compatibility
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
30
37
  - - ">="
31
38
  - !ruby/object:Gem::Version
32
- version: '4.0'
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rake
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -62,16 +76,16 @@ dependencies:
62
76
  name: yard
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
- - - "~>"
79
+ - - ">="
66
80
  - !ruby/object:Gem::Version
67
- version: '0.8'
81
+ version: 0.9.20
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - "~>"
86
+ - - ">="
73
87
  - !ruby/object:Gem::Version
74
- version: '0.8'
88
+ version: 0.9.20
75
89
  description: A tree structure for Mongoid documents using the materialized path pattern
76
90
  email:
77
91
  - benedikt@synatic.net
@@ -79,25 +93,27 @@ executables: []
79
93
  extensions: []
80
94
  extra_rdoc_files: []
81
95
  files:
82
- - ".rspec"
83
96
  - Gemfile
84
97
  - LICENSE
85
98
  - README.md
86
99
  - Rakefile
87
100
  - lib/mongoid/tree.rb
101
+ - lib/mongoid/tree/counter_caching.rb
88
102
  - lib/mongoid/tree/ordering.rb
89
103
  - lib/mongoid/tree/traversal.rb
104
+ - spec/mongoid/tree/counter_caching_spec.rb
90
105
  - spec/mongoid/tree/ordering_spec.rb
91
106
  - spec/mongoid/tree/traversal_spec.rb
92
107
  - spec/mongoid/tree_spec.rb
93
108
  - spec/spec_helper.rb
109
+ - spec/support/logger.rb
94
110
  - spec/support/macros/tree_macros.rb
95
111
  - spec/support/models/node.rb
96
112
  homepage: https://github.com/benedikt/mongoid-tree
97
113
  licenses:
98
114
  - MIT
99
115
  metadata: {}
100
- post_install_message:
116
+ post_install_message:
101
117
  rdoc_options: []
102
118
  require_paths:
103
119
  - lib
@@ -112,10 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
128
  - !ruby/object:Gem::Version
113
129
  version: '0'
114
130
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.5.1
117
- signing_key:
131
+ rubygems_version: 3.4.1
132
+ signing_key:
118
133
  specification_version: 4
119
134
  summary: A tree structure for Mongoid documents
120
135
  test_files: []
121
- has_rdoc:
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format documentation