rails_graph 0.2.0 → 0.4.0
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/.ruby-version +1 -1
- data/.tool-versions +1 -1
- data/Gemfile.lock +49 -52
- data/README.md +14 -6
- data/lib/rails_graph/commands/build_graph.rb +10 -4
- data/lib/rails_graph/commands/builders/associations.rb +63 -0
- data/lib/rails_graph/commands/builders/databases.rb +3 -1
- data/lib/rails_graph/commands/builders/gems_builder.rb +68 -0
- data/lib/rails_graph/commands/builders/models.rb +13 -16
- data/lib/rails_graph/commands/builders/packs.rb +3 -1
- data/lib/rails_graph/configuration.rb +6 -1
- data/lib/rails_graph/exporters/cypher.rb +7 -1
- data/lib/rails_graph/graph/nodes/database.rb +2 -2
- data/lib/rails_graph/graph/nodes/gem.rb +35 -0
- data/lib/rails_graph/helpers/models.rb +2 -0
- data/lib/rails_graph/inspector.rb +31 -0
- data/lib/rails_graph/version.rb +1 -1
- data/lib/rails_graph.rb +1 -0
- metadata +9 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a941a0470a1b02c82bab156a908ccd4e44fefe6c55de286aac071124c87ca3d7
|
|
4
|
+
data.tar.gz: d313e6ad0f56c18d7026e8f199752f318a771f5bd6f07d5484f58b590d8c3255
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7e9c40831fa2b9077efdc0e7d05ebb0f769fd8c118f6a472d2b5f4edd258db50f8dd281b00cb4e8565b236e5b1f467d13f86db36e038c92b209d4f950fae3af4
|
|
7
|
+
data.tar.gz: b5bfc0cd608cc3d0ba77724ac8fd28bfc2c81f32e79a95e23bd1eaac62f922c2928460fd682be5374149c1d7a86121dffccbbf0d08f1c6f1287e5cce60e6d759
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-3.
|
|
1
|
+
ruby-3.2.3
|
data/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby 3.
|
|
1
|
+
ruby 3.2.3
|
data/Gemfile.lock
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rails_graph (0.
|
|
5
|
-
activerecord (>= 6.0
|
|
6
|
-
neo4j-ruby-driver (>= 4.4
|
|
7
|
-
railties (>= 6.0
|
|
4
|
+
rails_graph (0.4.0)
|
|
5
|
+
activerecord (>= 6.0)
|
|
6
|
+
neo4j-ruby-driver (>= 4.4)
|
|
7
|
+
railties (>= 6.0)
|
|
8
8
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
actionpack (7.0.
|
|
13
|
-
actionview (= 7.0.
|
|
14
|
-
activesupport (= 7.0.
|
|
15
|
-
rack (~> 2.0, >= 2.2.
|
|
12
|
+
actionpack (7.0.5)
|
|
13
|
+
actionview (= 7.0.5)
|
|
14
|
+
activesupport (= 7.0.5)
|
|
15
|
+
rack (~> 2.0, >= 2.2.4)
|
|
16
16
|
rack-test (>= 0.6.3)
|
|
17
17
|
rails-dom-testing (~> 2.0)
|
|
18
18
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
19
|
-
actionview (7.0.
|
|
20
|
-
activesupport (= 7.0.
|
|
19
|
+
actionview (7.0.5)
|
|
20
|
+
activesupport (= 7.0.5)
|
|
21
21
|
builder (~> 3.1)
|
|
22
22
|
erubi (~> 1.4)
|
|
23
23
|
rails-dom-testing (~> 2.0)
|
|
24
24
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
25
|
-
activemodel (7.0.
|
|
26
|
-
activesupport (= 7.0.
|
|
27
|
-
activerecord (7.0.
|
|
28
|
-
activemodel (= 7.0.
|
|
29
|
-
activesupport (= 7.0.
|
|
30
|
-
activesupport (7.0.
|
|
25
|
+
activemodel (7.0.5)
|
|
26
|
+
activesupport (= 7.0.5)
|
|
27
|
+
activerecord (7.0.5)
|
|
28
|
+
activemodel (= 7.0.5)
|
|
29
|
+
activesupport (= 7.0.5)
|
|
30
|
+
activesupport (7.0.5)
|
|
31
31
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
32
32
|
i18n (>= 1.6, < 2)
|
|
33
33
|
minitest (>= 5.1)
|
|
@@ -48,30 +48,26 @@ GEM
|
|
|
48
48
|
diff-lcs (1.5.0)
|
|
49
49
|
erubi (1.12.0)
|
|
50
50
|
fiber-local (1.0.0)
|
|
51
|
-
i18n (1.
|
|
51
|
+
i18n (1.14.0)
|
|
52
52
|
concurrent-ruby (~> 1.0)
|
|
53
53
|
io-event (1.2.2)
|
|
54
|
-
json (2.6.
|
|
54
|
+
json (2.6.3)
|
|
55
55
|
loofah (2.21.3)
|
|
56
56
|
crass (~> 1.0.2)
|
|
57
57
|
nokogiri (>= 1.12.0)
|
|
58
58
|
method_source (1.0.0)
|
|
59
|
-
mini_portile2 (2.8.2)
|
|
60
59
|
minitest (5.18.0)
|
|
61
60
|
neo4j-ruby-driver (4.4.4)
|
|
62
61
|
activesupport
|
|
63
62
|
async-io
|
|
64
63
|
connection_pool
|
|
65
64
|
zeitwerk (>= 2.1.10)
|
|
66
|
-
nokogiri (1.15.
|
|
67
|
-
mini_portile2 (~> 2.8.2)
|
|
65
|
+
nokogiri (1.15.2-arm64-darwin)
|
|
68
66
|
racc (~> 1.4)
|
|
69
|
-
nokogiri (1.15.
|
|
67
|
+
nokogiri (1.15.2-x86_64-linux)
|
|
70
68
|
racc (~> 1.4)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
parallel (1.22.1)
|
|
74
|
-
parser (3.1.2.1)
|
|
69
|
+
parallel (1.23.0)
|
|
70
|
+
parser (3.2.2.1)
|
|
75
71
|
ast (~> 2.4.1)
|
|
76
72
|
racc (1.6.2)
|
|
77
73
|
rack (2.2.7)
|
|
@@ -80,50 +76,51 @@ GEM
|
|
|
80
76
|
rails-dom-testing (2.0.3)
|
|
81
77
|
activesupport (>= 4.2.0)
|
|
82
78
|
nokogiri (>= 1.6)
|
|
83
|
-
rails-html-sanitizer (1.
|
|
84
|
-
loofah (~> 2.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
rails-html-sanitizer (1.6.0)
|
|
80
|
+
loofah (~> 2.21)
|
|
81
|
+
nokogiri (~> 1.14)
|
|
82
|
+
railties (7.0.5)
|
|
83
|
+
actionpack (= 7.0.5)
|
|
84
|
+
activesupport (= 7.0.5)
|
|
88
85
|
method_source
|
|
89
86
|
rake (>= 12.2)
|
|
90
87
|
thor (~> 1.0)
|
|
91
88
|
zeitwerk (~> 2.5)
|
|
92
89
|
rainbow (3.1.1)
|
|
93
90
|
rake (13.0.6)
|
|
94
|
-
regexp_parser (2.
|
|
91
|
+
regexp_parser (2.8.0)
|
|
95
92
|
rexml (3.2.5)
|
|
96
|
-
rspec (3.
|
|
97
|
-
rspec-core (~> 3.
|
|
98
|
-
rspec-expectations (~> 3.
|
|
99
|
-
rspec-mocks (~> 3.
|
|
100
|
-
rspec-core (3.
|
|
101
|
-
rspec-support (~> 3.
|
|
102
|
-
rspec-expectations (3.
|
|
93
|
+
rspec (3.12.0)
|
|
94
|
+
rspec-core (~> 3.12.0)
|
|
95
|
+
rspec-expectations (~> 3.12.0)
|
|
96
|
+
rspec-mocks (~> 3.12.0)
|
|
97
|
+
rspec-core (3.12.2)
|
|
98
|
+
rspec-support (~> 3.12.0)
|
|
99
|
+
rspec-expectations (3.12.3)
|
|
103
100
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
104
|
-
rspec-support (~> 3.
|
|
105
|
-
rspec-mocks (3.
|
|
101
|
+
rspec-support (~> 3.12.0)
|
|
102
|
+
rspec-mocks (3.12.5)
|
|
106
103
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
107
|
-
rspec-support (~> 3.
|
|
108
|
-
rspec-support (3.
|
|
109
|
-
rubocop (1.
|
|
104
|
+
rspec-support (~> 3.12.0)
|
|
105
|
+
rspec-support (3.12.0)
|
|
106
|
+
rubocop (1.52.0)
|
|
110
107
|
json (~> 2.3)
|
|
111
108
|
parallel (~> 1.10)
|
|
112
|
-
parser (>= 3.
|
|
109
|
+
parser (>= 3.2.0.0)
|
|
113
110
|
rainbow (>= 2.2.2, < 4.0)
|
|
114
111
|
regexp_parser (>= 1.8, < 3.0)
|
|
115
112
|
rexml (>= 3.2.5, < 4.0)
|
|
116
|
-
rubocop-ast (>= 1.
|
|
113
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
117
114
|
ruby-progressbar (~> 1.7)
|
|
118
|
-
unicode-display_width (>=
|
|
119
|
-
rubocop-ast (1.
|
|
120
|
-
parser (>= 3.
|
|
121
|
-
ruby-progressbar (1.
|
|
115
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
116
|
+
rubocop-ast (1.29.0)
|
|
117
|
+
parser (>= 3.2.1.0)
|
|
118
|
+
ruby-progressbar (1.13.0)
|
|
122
119
|
thor (1.2.2)
|
|
123
120
|
timers (4.3.5)
|
|
124
121
|
tzinfo (2.0.6)
|
|
125
122
|
concurrent-ruby (~> 1.0)
|
|
126
|
-
unicode-display_width (2.
|
|
123
|
+
unicode-display_width (2.4.2)
|
|
127
124
|
zeitwerk (2.6.8)
|
|
128
125
|
|
|
129
126
|
PLATFORMS
|
|
@@ -138,4 +135,4 @@ DEPENDENCIES
|
|
|
138
135
|
rubocop (~> 1.21)
|
|
139
136
|
|
|
140
137
|
BUNDLED WITH
|
|
141
|
-
2.
|
|
138
|
+
2.4.13
|
data/README.md
CHANGED
|
@@ -8,6 +8,8 @@ Gain visibility on your Rails application data model and identify bottlenecks. I
|
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|
|
|
11
|
+
https://github.com/ahmad-elassuty/rails_graph/assets/4674035/53deb04e-f995-4af6-9496-a873f84b5445
|
|
12
|
+
|
|
11
13
|
## Features
|
|
12
14
|
|
|
13
15
|
- Application Databases and Tables
|
|
@@ -24,6 +26,7 @@ Gain visibility on your Rails application data model and identify bottlenecks. I
|
|
|
24
26
|
- ActiveRecord Abstract models
|
|
25
27
|
- Class Hierarchy
|
|
26
28
|
- [Packwerk](https://github.com/Shopify/packwerk) packages (disabled by default)
|
|
29
|
+
- Application Gems (disabled by default)
|
|
27
30
|
|
|
28
31
|
## Installation
|
|
29
32
|
|
|
@@ -59,23 +62,28 @@ You can control what RailsGraph will include in the final graph by:
|
|
|
59
62
|
# config/initializers/rails_graph.rb
|
|
60
63
|
|
|
61
64
|
RailsGraph.configure do |config|
|
|
62
|
-
#
|
|
65
|
+
# Explicitly define classes that are not loaded automatically
|
|
63
66
|
config.include_classes = [ActsAsTaggableOn::Tag, ActsAsTaggableOn::Tagging]
|
|
64
67
|
|
|
65
|
-
#
|
|
68
|
+
# Enable Columns visualisation
|
|
66
69
|
# default false
|
|
67
70
|
config.columns = true
|
|
68
71
|
|
|
69
|
-
#
|
|
72
|
+
# Enable Class Hierarchy visualisation
|
|
73
|
+
# default true
|
|
70
74
|
config.inheritance = true
|
|
71
75
|
|
|
72
|
-
#
|
|
76
|
+
# Enable Databases visualisation
|
|
73
77
|
# default true
|
|
74
|
-
config.
|
|
78
|
+
config.databases = false
|
|
75
79
|
|
|
76
|
-
#
|
|
80
|
+
# Enable Packwerk packages visualisation
|
|
77
81
|
# default false
|
|
78
82
|
config.include_packwerk = true
|
|
83
|
+
|
|
84
|
+
# Enable Gems visualisation
|
|
85
|
+
# default false
|
|
86
|
+
config.gems = true
|
|
79
87
|
end
|
|
80
88
|
```
|
|
81
89
|
|
|
@@ -7,6 +7,7 @@ require_relative "../graph/relationship"
|
|
|
7
7
|
require_relative "../graph/nodes/abstract_model"
|
|
8
8
|
require_relative "../graph/nodes/column"
|
|
9
9
|
require_relative "../graph/nodes/database"
|
|
10
|
+
require_relative "../graph/nodes/gem"
|
|
10
11
|
require_relative "../graph/nodes/model"
|
|
11
12
|
require_relative "../graph/nodes/pack"
|
|
12
13
|
require_relative "../graph/nodes/table"
|
|
@@ -21,9 +22,11 @@ require_relative "../graph/relationships/pack_model"
|
|
|
21
22
|
require_relative "../helpers/associations"
|
|
22
23
|
require_relative "../helpers/models"
|
|
23
24
|
|
|
25
|
+
require_relative "./builders/associations"
|
|
24
26
|
require_relative "./builders/models"
|
|
25
27
|
require_relative "./builders/packs"
|
|
26
28
|
require_relative "./builders/databases"
|
|
29
|
+
require_relative "./builders/gems_builder"
|
|
27
30
|
|
|
28
31
|
module RailsGraph
|
|
29
32
|
module Commands
|
|
@@ -35,21 +38,24 @@ module RailsGraph
|
|
|
35
38
|
def call
|
|
36
39
|
setup_generic_nodes
|
|
37
40
|
|
|
38
|
-
RailsGraph::Commands::Builders::
|
|
39
|
-
RailsGraph::Commands::Builders::
|
|
40
|
-
RailsGraph::Commands::Builders::
|
|
41
|
+
RailsGraph::Commands::Builders::GemsBuilder.enrich(graph: graph, configuration: configuration)
|
|
42
|
+
RailsGraph::Commands::Builders::Databases.enrich(graph: graph, configuration: configuration)
|
|
43
|
+
RailsGraph::Commands::Builders::Models.enrich(inspector: inspector, graph: graph, classes: classes,
|
|
44
|
+
configuration: configuration)
|
|
45
|
+
RailsGraph::Commands::Builders::Packs.enrich(graph: graph, configuration: configuration)
|
|
41
46
|
|
|
42
47
|
graph
|
|
43
48
|
end
|
|
44
49
|
|
|
45
50
|
private
|
|
46
51
|
|
|
47
|
-
attr_reader :configuration, :classes, :graph
|
|
52
|
+
attr_reader :configuration, :classes, :graph, :inspector
|
|
48
53
|
|
|
49
54
|
def initialize(configuration:)
|
|
50
55
|
@configuration = configuration
|
|
51
56
|
@classes = ActiveRecord::Base.descendants + configuration.include_classes
|
|
52
57
|
@graph = RailsGraph::Graph::Graph.new
|
|
58
|
+
@inspector = RailsGraph::Inspector.new
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
def setup_generic_nodes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsGraph
|
|
4
|
+
module Commands
|
|
5
|
+
module Builders
|
|
6
|
+
class Associations
|
|
7
|
+
attr_reader :graph, :inspector
|
|
8
|
+
|
|
9
|
+
def self.enrich(...)
|
|
10
|
+
new(...).enrich
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def enrich
|
|
14
|
+
build_associations_relationships
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
attr_reader :classes
|
|
20
|
+
|
|
21
|
+
def initialize(inspector:, graph:, classes:)
|
|
22
|
+
@inspector = inspector
|
|
23
|
+
@graph = graph
|
|
24
|
+
@classes = classes
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def build_associations_relationships
|
|
28
|
+
classes.each do |model|
|
|
29
|
+
model.reflect_on_all_associations.each do |association|
|
|
30
|
+
association.check_validity!
|
|
31
|
+
|
|
32
|
+
source_node, target_node = fetch_association_nodes(graph, association)
|
|
33
|
+
next report_invalid_class(model) if source_node.nil? || target_node.nil?
|
|
34
|
+
|
|
35
|
+
add_relationship(association, source_node, target_node)
|
|
36
|
+
rescue ActiveRecord::ActiveRecordError => _e
|
|
37
|
+
report_invalid_association(association)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def fetch_association_nodes(graph, association)
|
|
43
|
+
source_node = RailsGraph::Helpers::Associations.source_node(graph, association)
|
|
44
|
+
target_node = RailsGraph::Helpers::Associations.target_node(graph, association)
|
|
45
|
+
[source_node, target_node]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def add_relationship(association, source_node, target_node)
|
|
49
|
+
relationship = RailsGraph::Graph::Relationships::Association.new(association, source_node, target_node)
|
|
50
|
+
graph.add_relationship(relationship)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def report_invalid_association(association)
|
|
54
|
+
inspector.add_association(association)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def report_invalid_class(klass)
|
|
58
|
+
inspector.add_class(klass)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsGraph
|
|
4
|
+
module Commands
|
|
5
|
+
module Builders
|
|
6
|
+
class GemsBuilder
|
|
7
|
+
def self.enrich(graph:, configuration:)
|
|
8
|
+
return unless configuration.gems?
|
|
9
|
+
|
|
10
|
+
new(graph: graph).enrich
|
|
11
|
+
|
|
12
|
+
graph
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def enrich
|
|
16
|
+
build_gems_nodes
|
|
17
|
+
|
|
18
|
+
gems.each do |specifications|
|
|
19
|
+
source_node = graph.node("gem_#{specifications.name}")
|
|
20
|
+
|
|
21
|
+
# build_authored_by_relationships(specifications, source_node)
|
|
22
|
+
build_depends_on_gem_relationships(specifications, source_node)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
attr_reader :graph
|
|
29
|
+
|
|
30
|
+
def initialize(graph:)
|
|
31
|
+
@graph = graph
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def build_gems_nodes
|
|
35
|
+
gems.each do |gem|
|
|
36
|
+
node = RailsGraph::Graph::Nodes::Gem.new(gem)
|
|
37
|
+
graph.add_node(node)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# def build_authored_by_relationships(specifications); end
|
|
42
|
+
|
|
43
|
+
def build_depends_on_gem_relationships(specifications, source_node)
|
|
44
|
+
specifications.dependencies.each do |dependency|
|
|
45
|
+
target_node = graph.node("gem_#{dependency.name}")
|
|
46
|
+
add_depends_on_gem_relationship(source_node, target_node, dependency)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def add_depends_on_gem_relationship(source_node, target_node, dependency)
|
|
51
|
+
relationship = RailsGraph::Graph::Relationship.new(
|
|
52
|
+
source: source_node,
|
|
53
|
+
target: target_node,
|
|
54
|
+
label: "DependsOnGem",
|
|
55
|
+
name: "depends_on_gem",
|
|
56
|
+
properties: { type: dependency.type, requirement: dependency.requirement.to_s }
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
graph.add_relationship(relationship)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def gems
|
|
63
|
+
@gems ||= Gem::Specification.all
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -4,25 +4,29 @@ module RailsGraph
|
|
|
4
4
|
module Commands
|
|
5
5
|
module Builders
|
|
6
6
|
class Models
|
|
7
|
-
|
|
8
|
-
new(graph: graph, classes: classes, configuration: configuration).enrich
|
|
7
|
+
attr_reader :graph, :inspector
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
def self.enrich(...)
|
|
10
|
+
new(...).enrich
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def enrich
|
|
14
14
|
build_model_nodes
|
|
15
|
-
|
|
15
|
+
build_associations
|
|
16
16
|
build_column_nodes if configuration.columns?
|
|
17
17
|
build_model_table_relationships if configuration.databases?
|
|
18
18
|
build_inheritance_relationships if configuration.inheritance?
|
|
19
|
+
|
|
20
|
+
inspector.log
|
|
21
|
+
graph
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
private
|
|
22
25
|
|
|
23
|
-
attr_reader :
|
|
26
|
+
attr_reader :classes, :configuration
|
|
24
27
|
|
|
25
|
-
def initialize(graph:, classes:, configuration:)
|
|
28
|
+
def initialize(inspector:, graph:, classes:, configuration:)
|
|
29
|
+
@inspector = inspector
|
|
26
30
|
@graph = graph
|
|
27
31
|
@configuration = configuration
|
|
28
32
|
@classes = classes
|
|
@@ -41,16 +45,8 @@ module RailsGraph
|
|
|
41
45
|
end
|
|
42
46
|
end
|
|
43
47
|
|
|
44
|
-
def
|
|
45
|
-
|
|
46
|
-
model.reflect_on_all_associations.each do |association|
|
|
47
|
-
source_node = RailsGraph::Helpers::Associations.source_node(graph, association)
|
|
48
|
-
target_node = RailsGraph::Helpers::Associations.target_node(graph, association)
|
|
49
|
-
|
|
50
|
-
relationship = RailsGraph::Graph::Relationships::Association.new(association, source_node, target_node)
|
|
51
|
-
graph.add_relationship(relationship)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
48
|
+
def build_associations
|
|
49
|
+
Builders::Associations.enrich(inspector: inspector, graph: graph, classes: classes)
|
|
54
50
|
end
|
|
55
51
|
|
|
56
52
|
def build_column_nodes
|
|
@@ -91,6 +87,7 @@ module RailsGraph
|
|
|
91
87
|
|
|
92
88
|
identifier = RailsGraph::Helpers::Models.identifier(model)
|
|
93
89
|
node = graph.node(identifier)
|
|
90
|
+
|
|
94
91
|
relationship = build_represents_table_relationship(node, table_node)
|
|
95
92
|
graph.add_relationship(relationship)
|
|
96
93
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RailsGraph
|
|
4
4
|
class Configuration
|
|
5
5
|
attr_reader :include_classes
|
|
6
|
-
attr_writer :columns, :inheritance, :include_packwerk, :databases
|
|
6
|
+
attr_writer :columns, :inheritance, :include_packwerk, :databases, :gems
|
|
7
7
|
|
|
8
8
|
def initialize
|
|
9
9
|
@include_classes = []
|
|
@@ -11,6 +11,7 @@ module RailsGraph
|
|
|
11
11
|
@databases = true
|
|
12
12
|
@columns = false
|
|
13
13
|
@inheritance = true
|
|
14
|
+
@gems = false
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def include_classes=(include_classes)
|
|
@@ -32,5 +33,9 @@ module RailsGraph
|
|
|
32
33
|
def databases?
|
|
33
34
|
@databases
|
|
34
35
|
end
|
|
36
|
+
|
|
37
|
+
def gems?
|
|
38
|
+
@gems
|
|
39
|
+
end
|
|
35
40
|
end
|
|
36
41
|
end
|
|
@@ -32,7 +32,7 @@ module RailsGraph
|
|
|
32
32
|
|
|
33
33
|
item.properties.each do |k, v|
|
|
34
34
|
formatted_value = case v
|
|
35
|
-
when String, Symbol then "'#{v}'"
|
|
35
|
+
when String, Symbol then "'#{escape_quotes(v)}'"
|
|
36
36
|
when nil then "null"
|
|
37
37
|
else v.to_s
|
|
38
38
|
end
|
|
@@ -57,6 +57,12 @@ module RailsGraph
|
|
|
57
57
|
|
|
58
58
|
"CREATE (#{source_ref})-[:#{relationship.label} {#{format_properties(relationship)}}]->(#{target_ref})"
|
|
59
59
|
end
|
|
60
|
+
|
|
61
|
+
def self.escape_quotes(value)
|
|
62
|
+
return value if value.is_a? Symbol
|
|
63
|
+
|
|
64
|
+
value.gsub("'") { "\\'" }
|
|
65
|
+
end
|
|
60
66
|
end
|
|
61
67
|
end
|
|
62
68
|
end
|
|
@@ -28,8 +28,8 @@ module RailsGraph
|
|
|
28
28
|
replica: configs.replica? || false,
|
|
29
29
|
database_name: configs.database,
|
|
30
30
|
reaping_frequency: configs.reaping_frequency,
|
|
31
|
-
min_threads: configs.min_threads,
|
|
32
|
-
max_threads: configs.max_threads
|
|
31
|
+
min_threads: configs.try(:min_threads),
|
|
32
|
+
max_threads: configs.try(:max_threads)
|
|
33
33
|
}
|
|
34
34
|
end
|
|
35
35
|
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../node"
|
|
4
|
+
|
|
5
|
+
module RailsGraph
|
|
6
|
+
module Graph
|
|
7
|
+
module Nodes
|
|
8
|
+
class Gem < Node
|
|
9
|
+
attr_reader :specifications
|
|
10
|
+
|
|
11
|
+
def initialize(specifications)
|
|
12
|
+
@specifications = specifications
|
|
13
|
+
|
|
14
|
+
super(labels: "Gem", name: specifications.name, properties: build_properties)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def identifier
|
|
18
|
+
"gem_#{name}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def build_properties
|
|
24
|
+
{
|
|
25
|
+
description: specifications.description,
|
|
26
|
+
summary: specifications.summary,
|
|
27
|
+
homepage: specifications.homepage,
|
|
28
|
+
version: specifications.version.to_s,
|
|
29
|
+
licenses: specifications.licenses
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "set"
|
|
4
|
+
|
|
5
|
+
module RailsGraph
|
|
6
|
+
class Inspector
|
|
7
|
+
def initialize
|
|
8
|
+
@classes = Set.new
|
|
9
|
+
@associations = Set.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_class(klass)
|
|
13
|
+
@classes.add(klass)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_association(association)
|
|
17
|
+
@associations.add(association)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def log
|
|
21
|
+
@classes.each do |klass|
|
|
22
|
+
puts "[WARN][RailsGraph]: Invalid class configuration: #{klass}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@associations.each do |association|
|
|
26
|
+
puts "[WARN][RailsGraph]: #{association.name} association defined " \
|
|
27
|
+
"under #{association.active_record.name} class has invalid configurations!"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/rails_graph/version.rb
CHANGED
data/lib/rails_graph.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_graph
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ahmad Elassuty
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -17,9 +17,6 @@ dependencies:
|
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '6.0'
|
|
20
|
-
- - "<"
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: '7.1'
|
|
23
20
|
type: :runtime
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -27,23 +24,20 @@ dependencies:
|
|
|
27
24
|
- - ">="
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
26
|
version: '6.0'
|
|
30
|
-
- - "<"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '7.1'
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
28
|
name: neo4j-ruby-driver
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
|
36
30
|
requirements:
|
|
37
31
|
- - ">="
|
|
38
32
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 4.4
|
|
33
|
+
version: '4.4'
|
|
40
34
|
type: :runtime
|
|
41
35
|
prerelease: false
|
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
43
37
|
requirements:
|
|
44
38
|
- - ">="
|
|
45
39
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 4.4
|
|
40
|
+
version: '4.4'
|
|
47
41
|
- !ruby/object:Gem::Dependency
|
|
48
42
|
name: railties
|
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -51,9 +45,6 @@ dependencies:
|
|
|
51
45
|
- - ">="
|
|
52
46
|
- !ruby/object:Gem::Version
|
|
53
47
|
version: '6.0'
|
|
54
|
-
- - "<"
|
|
55
|
-
- !ruby/object:Gem::Version
|
|
56
|
-
version: '7.1'
|
|
57
48
|
type: :runtime
|
|
58
49
|
prerelease: false
|
|
59
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -61,9 +52,6 @@ dependencies:
|
|
|
61
52
|
- - ">="
|
|
62
53
|
- !ruby/object:Gem::Version
|
|
63
54
|
version: '6.0'
|
|
64
|
-
- - "<"
|
|
65
|
-
- !ruby/object:Gem::Version
|
|
66
|
-
version: '7.1'
|
|
67
55
|
description:
|
|
68
56
|
email:
|
|
69
57
|
- ahmad.elassuty@gmail.com
|
|
@@ -85,7 +73,9 @@ files:
|
|
|
85
73
|
- graph.svg
|
|
86
74
|
- lib/rails_graph.rb
|
|
87
75
|
- lib/rails_graph/commands/build_graph.rb
|
|
76
|
+
- lib/rails_graph/commands/builders/associations.rb
|
|
88
77
|
- lib/rails_graph/commands/builders/databases.rb
|
|
78
|
+
- lib/rails_graph/commands/builders/gems_builder.rb
|
|
89
79
|
- lib/rails_graph/commands/builders/models.rb
|
|
90
80
|
- lib/rails_graph/commands/builders/packs.rb
|
|
91
81
|
- lib/rails_graph/commands/export_graph.rb
|
|
@@ -101,6 +91,7 @@ files:
|
|
|
101
91
|
- lib/rails_graph/graph/nodes/abstract_model.rb
|
|
102
92
|
- lib/rails_graph/graph/nodes/column.rb
|
|
103
93
|
- lib/rails_graph/graph/nodes/database.rb
|
|
94
|
+
- lib/rails_graph/graph/nodes/gem.rb
|
|
104
95
|
- lib/rails_graph/graph/nodes/model.rb
|
|
105
96
|
- lib/rails_graph/graph/nodes/pack.rb
|
|
106
97
|
- lib/rails_graph/graph/nodes/table.rb
|
|
@@ -114,6 +105,7 @@ files:
|
|
|
114
105
|
- lib/rails_graph/helpers/associations.rb
|
|
115
106
|
- lib/rails_graph/helpers/models.rb
|
|
116
107
|
- lib/rails_graph/helpers/options_parser.rb
|
|
108
|
+
- lib/rails_graph/inspector.rb
|
|
117
109
|
- lib/rails_graph/railtie.rb
|
|
118
110
|
- lib/rails_graph/tasks/rails_graph.rake
|
|
119
111
|
- lib/rails_graph/version.rb
|
|
@@ -141,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
141
133
|
- !ruby/object:Gem::Version
|
|
142
134
|
version: '0'
|
|
143
135
|
requirements: []
|
|
144
|
-
rubygems_version: 3.
|
|
136
|
+
rubygems_version: 3.4.19
|
|
145
137
|
signing_key:
|
|
146
138
|
specification_version: 4
|
|
147
139
|
summary: Graph visualization for Rails applications.
|