ancestry 3.0.3 → 3.0.4

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: c1c70fafe20e537ed6cb98a60e671dc01fd540ac
4
- data.tar.gz: 583d3382374a761c553d99329f71be36ac423222
3
+ metadata.gz: a5bb7b7759117d88e5bec4658c6c4d691549f606
4
+ data.tar.gz: 0314da6d13466c30a6d21252083f37bbf5304bc5
5
5
  SHA512:
6
- metadata.gz: 55df9269223d805cd09f8fb87b5e0a25cad36aaad892e3527217cd086e15c6105e5552c0d7cd108645fe9a947712986a0885252f4b71a861eec1525be374f0b7
7
- data.tar.gz: 3f8ea178c2f3cc918ddd1fb79f8af4e3b8ed63704cd764bed42d8fb79da3b5316ab7160871eade25f8af9aac3bb004a298abc59f17e5b9759085c1ef8eb3c41d
6
+ metadata.gz: 2bcd4bc5dcf11e3aab9242990a98aefb18bdbb6c7de506d501689de9514ed664467d008037f5699dde52ebe4c5e27e655682d243c6b6fbd394e48eb40766906f
7
+ data.tar.gz: 7eddc0d2e5e9a46e7e8404b7447681f0205c7fa7db4075a410c73301cd31ce99988e0087b217a3cd0d7491411c4457e83628d41baf39489038af5ae87a00ec54
@@ -27,32 +27,27 @@ module Ancestry
27
27
  end
28
28
  end
29
29
 
30
- # Arrangement
30
+ # Get all nodes and sorting them into an empty hash
31
31
  def arrange options = {}
32
- # Get all nodes ordered by ancestry and start sorting them into an empty hash
33
- arrange_nodes self.ancestry_base_class.reorder(options.delete(:order)).where(options)
32
+ if (order = options.delete(:order))
33
+ arrange_nodes self.ancestry_base_class.order(order).where(options)
34
+ else
35
+ arrange_nodes self.ancestry_base_class.where(options)
36
+ end
34
37
  end
35
38
 
36
39
  # Arrange array of nodes into a nested hash of the form
37
40
  # {node => children}, where children = {} if the node has no children
41
+ # If a node's parent is not included, the node will be included as if it is a top level node
38
42
  def arrange_nodes(nodes)
39
- arranged = ActiveSupport::OrderedHash.new
40
- min_depth = Float::INFINITY
41
- index = Hash.new { |h, k| h[k] = ActiveSupport::OrderedHash.new }
43
+ node_ids = Set.new(nodes.map(&:id))
44
+ index = Hash.new { |h, k| h[k] = {} }
42
45
 
43
- nodes.each do |node|
46
+ nodes.each_with_object({}) do |node, arranged|
44
47
  children = index[node.id]
45
48
  index[node.parent_id][node] = children
46
-
47
- depth = node.depth
48
- if depth < min_depth
49
- min_depth = depth
50
- arranged.clear
51
- end
52
- arranged[node] = children if depth == min_depth
49
+ arranged[node] = children unless node_ids.include?(node.parent_id)
53
50
  end
54
-
55
- arranged
56
51
  end
57
52
 
58
53
  # Arrangement to nested array
@@ -221,7 +216,7 @@ module Ancestry
221
216
  if defined?(@primary_key_is_an_integer)
222
217
  @primary_key_is_an_integer
223
218
  else
224
- @primary_key_is_an_integer = !ANCESTRY_UNCAST_TYPES.include?(type_for_attribute(primary_key))
219
+ @primary_key_is_an_integer = !ANCESTRY_UNCAST_TYPES.include?(type_for_attribute(primary_key).type)
225
220
  end
226
221
  end
227
222
  end
@@ -1,3 +1,3 @@
1
1
  module Ancestry
2
- VERSION = "3.0.3"
2
+ VERSION = "3.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ancestry
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kroes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-23 00:00:00.000000000 Z
12
+ date: 2018-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord