awesome_nested_set 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 2.1.3
2
+ * Update child depth when parent node is moved. [Amanda Wagener]
3
+ * Added move_to_child_with_index. [Ben Zhang]
4
+ * Optimised self_and_descendants for when there's an index on lft. [Mark Torrance]
5
+ * Added support for an unsaved record to return the right 'root'. [Philip Arndt]
6
+
7
+ 2.1.2
8
+ * Fixed regressions introduced. [Philip Arndt]
9
+
1
10
  2.1.1
2
11
  * Added 'depth' which indicates how many levels deep the node is.
3
12
  This only works when you have a column called 'depth' in your table,
@@ -292,12 +292,20 @@ module CollectiveIdea #:nodoc:
292
292
 
293
293
  # Returns true is this is a child node
294
294
  def child?
295
- !parent_id.nil?
295
+ !root?
296
296
  end
297
297
 
298
298
  # Returns root
299
299
  def root
300
- self_and_ancestors.where(parent_column_name => nil).first
300
+ if persisted?
301
+ self_and_ancestors.where(parent_column_name => nil).first
302
+ else
303
+ if parent_id && current_parent = nested_set_scope.find(parent_id)
304
+ current_parent.root
305
+ else
306
+ self
307
+ end
308
+ end
301
309
  end
302
310
 
303
311
  # Returns the array of all parents and self
@@ -336,7 +344,8 @@ module CollectiveIdea #:nodoc:
336
344
  # Returns a set of itself and all of its nested children
337
345
  def self_and_descendants
338
346
  nested_set_scope.where([
339
- "#{self.class.quoted_table_name}.#{quoted_left_column_name} >= ? AND #{self.class.quoted_table_name}.#{quoted_right_column_name} <= ?", left, right
347
+ "#{self.class.quoted_table_name}.#{quoted_left_column_name} >= ? AND #{self.class.quoted_table_name}.#{quoted_left_column_name} < ?", left, right
348
+ # using _left_ for both sides here lets us benefit from an index on that column if one exists
340
349
  ])
341
350
  end
342
351
 
@@ -404,6 +413,17 @@ module CollectiveIdea #:nodoc:
404
413
  move_to node, :child
405
414
  end
406
415
 
416
+ # Move the node to the child of another node with specify index (you can pass id only)
417
+ def move_to_child_with_index(node, index)
418
+ if node.children.empty?
419
+ move_to_child_of(node)
420
+ elsif node.children.count == index
421
+ move_to_right_of(node.children.last)
422
+ else
423
+ move_to_left_of(node.children[index])
424
+ end
425
+ end
426
+
407
427
  # Move the node to root nodes
408
428
  def move_to_root
409
429
  move_to nil, :root
@@ -609,6 +629,7 @@ module CollectiveIdea #:nodoc:
609
629
  end
610
630
  target.reload_nested_set if target
611
631
  self.set_depth!
632
+ self.children.each(&:save)
612
633
  self.reload_nested_set
613
634
  end
614
635
  end
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedSet
2
- VERSION = '2.1.2' unless defined?(::AwesomeNestedSet::VERSION)
2
+ VERSION = '2.1.3' unless defined?(::AwesomeNestedSet::VERSION)
3
3
  end
metadata CHANGED
@@ -1,49 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: awesome_nested_set
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.3
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 1
9
- - 2
10
- version: 2.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Brandon Keepers
14
9
  - Daniel Morrison
15
10
  - Philip Arndt
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2012-01-26 00:00:00 Z
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
14
+ date: 2012-04-11 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
23
17
  name: activerecord
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
26
19
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 7
31
- segments:
32
- - 3
33
- - 0
34
- - 0
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
35
23
  version: 3.0.0
36
24
  type: :runtime
37
- version_requirements: *id001
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 3.0.0
38
32
  description: An awesome nested set implementation for Active Record
39
33
  email: info@collectiveidea.com
40
34
  executables: []
41
-
42
35
  extensions: []
43
-
44
- extra_rdoc_files:
36
+ extra_rdoc_files:
45
37
  - README.rdoc
46
- files:
38
+ files:
47
39
  - lib/awesome_nested_set/awesome_nested_set.rb
48
40
  - lib/awesome_nested_set/helper.rb
49
41
  - lib/awesome_nested_set/version.rb
@@ -53,39 +45,31 @@ files:
53
45
  - CHANGELOG
54
46
  homepage: http://github.com/collectiveidea/awesome_nested_set
55
47
  licenses: []
56
-
57
48
  post_install_message:
58
- rdoc_options:
49
+ rdoc_options:
59
50
  - --main
60
51
  - README.rdoc
61
52
  - --inline-source
62
53
  - --line-numbers
63
- require_paths:
54
+ require_paths:
64
55
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
66
57
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
63
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
83
68
  requirements: []
84
-
85
69
  rubyforge_project:
86
- rubygems_version: 1.8.10
70
+ rubygems_version: 1.8.19
87
71
  signing_key:
88
72
  specification_version: 3
89
73
  summary: An awesome nested set implementation for Active Record
90
74
  test_files: []
91
-
75
+ has_rdoc: