mongoid-tree 1.1.0 → 2.0.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
2
  SHA1:
3
- metadata.gz: 5137d0df514633dff660618929df94658352c576
4
- data.tar.gz: cc8bc0884e0d028b762d364ede0fca32b07e1e53
3
+ metadata.gz: b077e8bfb9c59a23025951349cc64293d496ff2b
4
+ data.tar.gz: a16ee9fa51743425d25de01fb489ac1f193752b6
5
5
  SHA512:
6
- metadata.gz: 6533082d31a625ccb70529cdd4391ce9f0a934239efe3c45c1299a9e2762db2d4af26933a2b48bc3852b982b1f9a63174e486dedd714fba872a58e46f4f60699
7
- data.tar.gz: cd4b110278a8b0cf46be05a721eafc9428e0a3260e7434b72668ceea2a4f2327051967df4739c78f678a60fb19cc8b76f8c6223e73591b6f49faf5b3222bffd8
6
+ metadata.gz: b53ef6fb2bd5055dc441d43af840617806e48550328266d033b124f5d978c4e118627d3a1d95815d8e014c2eab6cd29f11936d6a605a292757163c931b85cacf
7
+ data.tar.gz: db8180d46265765c981e249ffd904f5d2d8b4414effda1e37402e3066512339ea9e820ed52ed6d58609bf5992163fc9a87372eb632aa1560ff1f1e5cce06109c
data/Gemfile CHANGED
@@ -4,4 +4,9 @@ gemspec
4
4
 
5
5
  gem 'guard-rspec', '>= 0.6.0'
6
6
  gem 'ruby_gntp', '>= 0.3.4'
7
- gem 'rb-fsevent' if RUBY_PLATFORM =~ /darwin/
7
+ gem 'rb-fsevent' if RUBY_PLATFORM =~ /darwin/
8
+ gem 'mongoid', :github => 'mongoid/mongoid'
9
+
10
+ platforms :rbx do
11
+ gem 'rubysl-rake', '~> 2.0'
12
+ end
data/README.md CHANGED
@@ -4,9 +4,10 @@ A tree structure for Mongoid documents using the materialized path pattern
4
4
 
5
5
  ## Requirements
6
6
 
7
- * mongoid (~> 3.0)
7
+ * mongoid (~> 4.0)
8
8
 
9
- For a mongoid 2.x compatible version, please use mongoid-tree 0.7.x!
9
+ For a mongoid 3.x compatible version, please use mongoid-tree 1.0.x,
10
+ for a mongoid 2.x compatible version, please use mongoid-tree 0.7.x.
10
11
 
11
12
 
12
13
  ## Install
@@ -17,15 +18,15 @@ To install mongoid_tree, simply add it to your Gemfile:
17
18
 
18
19
  In order to get the latest development version of mongoid-tree:
19
20
 
20
- gem 'mongoid-tree', :git => 'git://github.com/benedikt/mongoid-tree', :require => 'mongoid/tree'
21
+ gem 'mongoid-tree', :git => 'git://github.com/benedikt/mongoid-tree'
21
22
 
22
- You might want to remove the `:require => 'mongoid/tree'` 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
23
24
 
24
25
  bundle install
25
26
 
26
- ### Upgrade from mongoid-tree 1.0.x
27
+ ### Upgrade from mongoid-tree 1.x
27
28
 
28
- To fix issues with the ordering of ancestors, mongoid-tree 1.1 introduces a new depth field to the documents that include the Mongoid::Tree module. In case your project uses its own depth field, you can now rely on mongoid-tree to handle this.
29
+ To fix issues with the ordering of ancestors, mongoid-tree 2.0 introduces a new `depth` field to the documents that include the `Mongoid::Tree` module. In case your project uses its own `depth` field, you can now rely on mongoid-tree to handle this.
29
30
 
30
31
  ## Usage
31
32
 
@@ -277,7 +277,7 @@ module Mongoid
277
277
  #
278
278
  # @return [Mongoid::Criteria] Mongoid criteria to retrieve the documents ancestors
279
279
  def ancestors
280
- base_class.where(:_id.in => parent_ids).asc(:depth)
280
+ base_class.where(:_id.in => parent_ids).order(:depth => :asc)
281
281
  end
282
282
 
283
283
  ##
@@ -35,7 +35,7 @@ module Mongoid
35
35
  included do
36
36
  field :position, :type => Integer
37
37
 
38
- default_scope asc(:position)
38
+ default_scope ->{ asc(:position) }
39
39
 
40
40
  before_save :assign_default_position, :if => :assign_default_position?
41
41
  before_save :reposition_former_siblings, :if => :sibling_reposition_required?
@@ -157,11 +157,11 @@ module Mongoid
157
157
 
158
158
  if position > other.position
159
159
  new_position = other.position
160
- self.siblings_between(other).inc(:position, 1)
161
- other.inc(:position, 1)
160
+ self.siblings_between(other).inc(:position => 1)
161
+ other.inc(:position => 1)
162
162
  else
163
163
  new_position = other.position - 1
164
- self.siblings_between(other).inc(:position, -1)
164
+ self.siblings_between(other).inc(:position => -1)
165
165
  end
166
166
 
167
167
  self.position = new_position
@@ -181,11 +181,11 @@ module Mongoid
181
181
 
182
182
  if position > other.position
183
183
  new_position = other.position + 1
184
- self.siblings_between(other).inc(:position, 1)
184
+ self.siblings_between(other).inc(:position => 1)
185
185
  else
186
186
  new_position = other.position
187
- self.siblings_between(other).inc(:position, -1)
188
- other.inc(:position, -1)
187
+ self.siblings_between(other).inc(:position => -1)
188
+ other.inc(:position => -1)
189
189
  end
190
190
 
191
191
  self.position = new_position
@@ -195,8 +195,8 @@ module Mongoid
195
195
  private
196
196
 
197
197
  def switch_with_sibling_at_offset(offset)
198
- siblings.where(:position => self.position + offset).first.inc(:position, -offset)
199
- inc(:position, offset)
198
+ siblings.where(:position => self.position + offset).first.inc(:position => -offset)
199
+ inc(:position => offset)
200
200
  end
201
201
 
202
202
  def ensure_to_be_sibling_of(other)
@@ -206,14 +206,14 @@ module Mongoid
206
206
  end
207
207
 
208
208
  def move_lower_siblings_up
209
- lower_siblings.inc(:position, -1)
209
+ lower_siblings.inc(:position => -1)
210
210
  end
211
211
 
212
212
  def reposition_former_siblings
213
213
  former_siblings = base_class.where(:parent_id => attribute_was('parent_id')).
214
214
  and(:position.gt => (attribute_was('position') || 0)).
215
215
  excludes(:id => self.id)
216
- former_siblings.inc(:position, -1)
216
+ former_siblings.inc(:position => -1)
217
217
  end
218
218
 
219
219
  def sibling_reposition_required?
@@ -141,7 +141,7 @@ describe Mongoid::Tree::Traversal do
141
141
  @root1 = node(:root1)
142
142
  @root2 = node(:root2)
143
143
 
144
- Node.stub(:roots).and_return [@root1, @root2]
144
+ allow(Node).to receive(:roots).and_return [@root1, @root2]
145
145
  end
146
146
 
147
147
  it 'should grab each root' do
@@ -10,7 +10,7 @@ describe Mongoid::Tree do
10
10
  expect(a.macro).to eq(:has_many)
11
11
  expect(a.class_name).to eq('Node')
12
12
  expect(a.foreign_key).to eq('parent_id')
13
- expect(Node.index_options).to have_key(:parent_id => 1)
13
+ expect(Node.index_specification(:parent_id => 1)).to be
14
14
  end
15
15
 
16
16
  it "should be referenced in one parent as inverse of children" do
@@ -26,14 +26,14 @@ describe Mongoid::Tree do
26
26
  expect(f).to be
27
27
  expect(f.options[:type]).to eq(Array)
28
28
  expect(f.options[:default]).to eq([])
29
- expect(Node.index_options).to have_key(:parent_ids => 1)
29
+ expect(Node.index_specification(:parent_ids => 1)).to be
30
30
  end
31
31
 
32
32
  it "should store the depth as Integer with index" do
33
33
  f = Node.fields['depth']
34
34
  expect(f).to be
35
35
  expect(f.options[:type]).to eq(Integer)
36
- expect(Node.index_options).to have_key(:depth => 1)
36
+ expect(Node.index_specification(:depth => 1)).to be
37
37
  end
38
38
 
39
39
  describe 'when new' do
@@ -263,11 +263,8 @@ describe Mongoid::Tree do
263
263
  end
264
264
 
265
265
  it "should be updated when the nodes ancestors change" do
266
- node(:child).update_attributes!(:parent => nil)
267
-
268
- puts node(:child).inspect
269
-
270
- expect(node(:child).reload.depth).to eq(0)
266
+ node(:child).update_attributes(:parent => nil)
267
+ expect(node(:child).depth).to eq(0)
271
268
  expect(node(:subchild).depth).to eq(1)
272
269
  end
273
270
  end
@@ -21,15 +21,16 @@ module Mongoid::Tree::TreeMacros
21
21
  end
22
22
 
23
23
  private
24
+
24
25
  def create_tree(object)
25
26
  case object
26
- when String then return create_node(object)
27
- when Array then object.each { |tree| create_tree(tree) }
28
- when Hash then
29
- name, children = object.first
30
- node = create_node(name)
31
- children.each { |c| node.children << create_tree(c) }
32
- return node
27
+ when String then return create_node(object)
28
+ when Array then object.each { |tree| create_tree(tree) }
29
+ when Hash then
30
+ name, children = object.first
31
+ node = create_node(name)
32
+ children.each { |c| node.children << create_tree(c) }
33
+ return node
33
34
  end
34
35
  end
35
36
 
@@ -4,8 +4,6 @@ class Node
4
4
  include Mongoid::Tree::Traversal
5
5
 
6
6
  field :name
7
-
8
- attr_accessible :name, :parent
9
7
  end
10
8
 
11
9
  class SubclassedNode < Node
@@ -23,8 +21,6 @@ class OrderedNode
23
21
  include Mongoid::Tree::Ordering
24
22
 
25
23
  field :name
26
-
27
- attr_accessible :name
28
24
  end
29
25
 
30
26
  class NodeWithEmbeddedDocument < Node
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benedikt Deicke
@@ -14,22 +14,22 @@ dependencies:
14
14
  name: mongoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - <
17
+ - - <=
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.0'
20
20
  - - '>='
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: '4.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - <
27
+ - - <=
28
28
  - !ruby/object:Gem::Version
29
- version: '4.0'
29
+ version: '5.0'
30
30
  - - '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '4.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '2.14'
53
+ version: '3.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ~>
59
59
  - !ruby/object:Gem::Version
60
- version: '2.14'
60
+ version: '3.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: yard
63
63
  requirement: !ruby/object:Gem::Requirement