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 +4 -4
- data/lib/ancestry/class_methods.rb +12 -17
- data/lib/ancestry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5bb7b7759117d88e5bec4658c6c4d691549f606
|
4
|
+
data.tar.gz: 0314da6d13466c30a6d21252083f37bbf5304bc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bcd4bc5dcf11e3aab9242990a98aefb18bdbb6c7de506d501689de9514ed664467d008037f5699dde52ebe4c5e27e655682d243c6b6fbd394e48eb40766906f
|
7
|
+
data.tar.gz: 7eddc0d2e5e9a46e7e8404b7447681f0205c7fa7db4075a410c73301cd31ce99988e0087b217a3cd0d7491411c4457e83628d41baf39489038af5ae87a00ec54
|
@@ -27,32 +27,27 @@ module Ancestry
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
#
|
30
|
+
# Get all nodes and sorting them into an empty hash
|
31
31
|
def arrange options = {}
|
32
|
-
|
33
|
-
|
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
|
-
|
40
|
-
|
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.
|
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
|
data/lib/ancestry/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2018-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|