hierarchy-tree 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hierarchy_tree.rb +21 -10
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c2620a107d595da64c5854efec9c90f4ebada54e79ea851e35cd698dd31cb7e
|
4
|
+
data.tar.gz: 3957eb61b1debe9dcff8049d89947a60b594b348f3e65b31f25615d4bb56a8de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfe0cdf719a378c501ac89db2df73349f9af3b131c39947e0ad3b9126032ca2898997fad85f4ae532b30fa11062e84fbc339c5a7d6e2cd7f092d486426a84040
|
7
|
+
data.tar.gz: 0b3677fe95dd795eb1ba93671e9878df59e712d4378c0a638cb62765f7bc49fef2e8ab8e91133934723afb2b91149a6984b25353d383911d7d516bd6539dd9bf
|
data/lib/hierarchy_tree.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'active_support/core_ext/object/inclusion.rb'
|
3
3
|
|
4
|
+
################ Debug ################
|
5
|
+
# rm hierarchy-tree-X.Y.Z.gem
|
6
|
+
# gem build hierarchy_tree
|
7
|
+
# gem install hierarchy-tree-X.Y.Z.gem
|
8
|
+
# ruby -Itest test/test_hierarchy_tree.rb
|
9
|
+
|
4
10
|
class Hierarchy
|
5
11
|
# Return the full hierarchy starting from the provided class
|
6
12
|
def self.associations(klass)
|
7
|
-
build_hierarchy(klass)
|
13
|
+
build_hierarchy(class: klass)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return the full hierarchy starting from the provided class
|
17
|
+
def self.classes(klass)
|
18
|
+
build_hierarchy(class: klass, classes?: true)
|
8
19
|
end
|
9
20
|
|
10
|
-
# Return
|
11
|
-
def self.
|
12
|
-
@
|
21
|
+
# Return an array o
|
22
|
+
def self.classes_list(klass)
|
23
|
+
@classes_list = []
|
13
24
|
build_descendants(klass)
|
14
|
-
@
|
25
|
+
@classes_list
|
15
26
|
end
|
16
27
|
|
17
28
|
def self.loop?(klass)
|
@@ -23,9 +34,9 @@ class Hierarchy
|
|
23
34
|
|
24
35
|
private_class_method
|
25
36
|
|
26
|
-
def self.build_hierarchy(
|
37
|
+
def self.build_hierarchy(opts)
|
27
38
|
@cache = {}
|
28
|
-
dfs_hierarchy(
|
39
|
+
dfs_hierarchy(opts)
|
29
40
|
rescue SystemStackError
|
30
41
|
Rails.logger.ap "Infinite loop detected and handled for #{opts[:class]} hierarchy", :warn
|
31
42
|
[]
|
@@ -81,13 +92,13 @@ class Hierarchy
|
|
81
92
|
def self.build_descendants(klass)
|
82
93
|
dfs_descendants(class: klass, classes?: true)
|
83
94
|
rescue SystemStackError
|
84
|
-
Rails.logger.ap "Infinite loop detected and handled for #{opts[:class]}
|
95
|
+
Rails.logger.ap "Infinite loop detected and handled for #{opts[:class]} classes_list", :warn
|
85
96
|
[]
|
86
97
|
end
|
87
98
|
|
88
99
|
def self.dfs_descendants(opts, klass_name = nil)
|
89
|
-
return if klass_name.in? @
|
90
|
-
@
|
100
|
+
return if klass_name.in? @classes_list
|
101
|
+
@classes_list.push(klass_name) if klass_name.present?
|
91
102
|
children_classes(opts).each do |child_klass, child_name|
|
92
103
|
child_opts = { class: child_klass, classes?: opts[:classes?] }
|
93
104
|
dfs_descendants(child_opts, child_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hierarchy-tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Cordeiro Costa
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '4.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4.2'
|
55
55
|
description: |-
|
@@ -66,7 +66,7 @@ homepage: https://github.com/Victorcorcos/hierarchy-tree
|
|
66
66
|
licenses:
|
67
67
|
- MIT
|
68
68
|
metadata: {}
|
69
|
-
post_install_message:
|
69
|
+
post_install_message:
|
70
70
|
rdoc_options: []
|
71
71
|
require_paths:
|
72
72
|
- lib
|
@@ -81,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
|
85
|
-
|
86
|
-
signing_key:
|
84
|
+
rubygems_version: 3.1.6
|
85
|
+
signing_key:
|
87
86
|
specification_version: 4
|
88
87
|
summary: hierarchy-tree is a gem that shows the whole hierarchy and the associations
|
89
88
|
related to a desired class.
|