optic-rails 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/optic/rails.rb +4 -22
- data/lib/optic/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97fdc801bf28a576a592e12560541b7803d2ca3d2d58594c8e0756662ff0ce46
|
4
|
+
data.tar.gz: 30a93912914bb03672659bd451a5f7961ee535e11f2262217dd6a4855c55015c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7dbd059fae6f6cbcffcea30116e29da453d86284f220f30551bb3cc49d65721799f097e835259259b5aa3afe284311441a5d55d057da666fb6d3a8e23287e1
|
7
|
+
data.tar.gz: 7715d60ca1acaf47d1c8c5b81ddc3cdda7d259e43855f01ef0897a0f0298c3330331e9a16fff9515d1d14db7a276fc36cec75b590072924bbaf7481eccc2e32d
|
data/lib/optic/rails.rb
CHANGED
@@ -57,13 +57,12 @@ module Optic
|
|
57
57
|
graph = RGL::DirectedAdjacencyGraph.new
|
58
58
|
|
59
59
|
base_klass = ApplicationRecord rescue ActiveRecord::Base
|
60
|
-
klasses = ObjectSpace.each_object(Class).find_all { |klass| klass < base_klass }
|
60
|
+
klasses = ObjectSpace.each_object(Class).find_all { |klass| klass < base_klass }.find_all(&:table_exists?)
|
61
61
|
|
62
62
|
graph.add_vertices *klasses
|
63
63
|
|
64
64
|
klasses.each do |klass|
|
65
65
|
klass.reflect_on_all_associations(:belongs_to).each do |reflection|
|
66
|
-
# p klass, reflection
|
67
66
|
next if reflection.options[:polymorphic] # TODO
|
68
67
|
|
69
68
|
# TODO should the source be reflection.active_record or klass?
|
@@ -77,29 +76,12 @@ module Optic
|
|
77
76
|
def self.get_entities
|
78
77
|
graph = entity_graph
|
79
78
|
|
80
|
-
#
|
81
|
-
|
82
|
-
vertices = graph.vertices
|
83
|
-
|
84
|
-
adjacency_matrix = Array.new(vertices.size) do |i|
|
85
|
-
Array.new(vertices.size) do |j|
|
86
|
-
0
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
graph.edges.each do |edge|
|
91
|
-
adjacency_matrix[vertices.index(edge.source)][vertices.index(edge.target)] = 1
|
92
|
-
end
|
93
|
-
|
94
|
-
# TODO run this calculation on the server instead, and pass the full graph (not just the node list)
|
95
|
-
page_rank = PageRank.new(adjacency_matrix)
|
96
|
-
init = Array.new(vertices.size, 1.0 / vertices.size.to_f)
|
97
|
-
ranks = page_rank.calc(init, alpha)
|
98
|
-
ranked_entities = vertices.zip(ranks).map { |v, r| { name: v.name, table_name: v.table_name, page_rank: r } }.sort_by { |record| record[:page_rank] }.reverse
|
79
|
+
# TODO send entire graph to server
|
80
|
+
entities = graph.vertices.map { |v| { name: v.name, table_name: v.table_name } }
|
99
81
|
|
100
82
|
{
|
101
83
|
schema_version: ActiveRecord::Migrator.current_version,
|
102
|
-
entities:
|
84
|
+
entities: entities # TODO also return entity attributes?
|
103
85
|
}
|
104
86
|
end
|
105
87
|
|
data/lib/optic/rails/version.rb
CHANGED