rails_graph 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2aa9e5821416a34e7eca9ba18199bea6007190821c50cabb84147db6232b06e2
4
- data.tar.gz: f54cb43940dba30d7ddc5915cb8669601d0e05b9b5eb4582c18a504859101ed0
3
+ metadata.gz: a941a0470a1b02c82bab156a908ccd4e44fefe6c55de286aac071124c87ca3d7
4
+ data.tar.gz: d313e6ad0f56c18d7026e8f199752f318a771f5bd6f07d5484f58b590d8c3255
5
5
  SHA512:
6
- metadata.gz: 714e4e3d097f8fda7958665d9f4f8ee0ca78978ecab77be2a59ad84fa1921c3204ae93d111072882068ce33ee3966786a3d7473d787e275077d61785f105815a
7
- data.tar.gz: f3889f7437868743a38971f1808e2b3e9d6ac8445a8567f3e96ebb7722d35a24795830f220bdf7eeb1940bfefe472c1cc33f2539a4bd380358af006ad4c62035
6
+ metadata.gz: 7e9c40831fa2b9077efdc0e7d05ebb0f769fd8c118f6a472d2b5f4edd258db50f8dd281b00cb4e8565b236e5b1f467d13f86db36e038c92b209d4f950fae3af4
7
+ data.tar.gz: b5bfc0cd608cc3d0ba77724ac8fd28bfc2c81f32e79a95e23bd1eaac62f922c2928460fd682be5374149c1d7a86121dffccbbf0d08f1c6f1287e5cce60e6d759
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.1.2
1
+ ruby-3.2.3
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.2
1
+ ruby 3.2.3
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_graph (0.3.0)
5
- activerecord (>= 6.0, < 7.1)
6
- neo4j-ruby-driver (>= 4.4.0.alpha.8)
7
- railties (>= 6.0, < 7.1)
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/
@@ -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.13.0)
51
+ i18n (1.14.0)
52
52
  concurrent-ruby (~> 1.0)
53
53
  io-event (1.2.2)
54
- json (2.6.2)
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.2)
67
- mini_portile2 (~> 2.8.2)
68
- racc (~> 1.4)
69
65
  nokogiri (1.15.2-arm64-darwin)
70
66
  racc (~> 1.4)
71
67
  nokogiri (1.15.2-x86_64-linux)
72
68
  racc (~> 1.4)
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)
@@ -92,39 +88,39 @@ GEM
92
88
  zeitwerk (~> 2.5)
93
89
  rainbow (3.1.1)
94
90
  rake (13.0.6)
95
- regexp_parser (2.5.0)
91
+ regexp_parser (2.8.0)
96
92
  rexml (3.2.5)
97
- rspec (3.11.0)
98
- rspec-core (~> 3.11.0)
99
- rspec-expectations (~> 3.11.0)
100
- rspec-mocks (~> 3.11.0)
101
- rspec-core (3.11.0)
102
- rspec-support (~> 3.11.0)
103
- rspec-expectations (3.11.1)
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)
104
100
  diff-lcs (>= 1.2.0, < 2.0)
105
- rspec-support (~> 3.11.0)
106
- rspec-mocks (3.11.1)
101
+ rspec-support (~> 3.12.0)
102
+ rspec-mocks (3.12.5)
107
103
  diff-lcs (>= 1.2.0, < 2.0)
108
- rspec-support (~> 3.11.0)
109
- rspec-support (3.11.1)
110
- rubocop (1.36.0)
104
+ rspec-support (~> 3.12.0)
105
+ rspec-support (3.12.0)
106
+ rubocop (1.52.0)
111
107
  json (~> 2.3)
112
108
  parallel (~> 1.10)
113
- parser (>= 3.1.2.1)
109
+ parser (>= 3.2.0.0)
114
110
  rainbow (>= 2.2.2, < 4.0)
115
111
  regexp_parser (>= 1.8, < 3.0)
116
112
  rexml (>= 3.2.5, < 4.0)
117
- rubocop-ast (>= 1.20.1, < 2.0)
113
+ rubocop-ast (>= 1.28.0, < 2.0)
118
114
  ruby-progressbar (~> 1.7)
119
- unicode-display_width (>= 1.4.0, < 3.0)
120
- rubocop-ast (1.21.0)
121
- parser (>= 3.1.1.0)
122
- ruby-progressbar (1.11.0)
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)
123
119
  thor (1.2.2)
124
120
  timers (4.3.5)
125
121
  tzinfo (2.0.6)
126
122
  concurrent-ruby (~> 1.0)
127
- unicode-display_width (2.3.0)
123
+ unicode-display_width (2.4.2)
128
124
  zeitwerk (2.6.8)
129
125
 
130
126
  PLATFORMS
@@ -139,4 +135,4 @@ DEPENDENCIES
139
135
  rubocop (~> 1.21)
140
136
 
141
137
  BUNDLED WITH
142
- 2.3.22
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
  ![Graph](graph.svg "Graph")
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
- # Configure extra classes that are not loaded automatically
65
+ # Explicitly define classes that are not loaded automatically
63
66
  config.include_classes = [ActsAsTaggableOn::Tag, ActsAsTaggableOn::Tagging]
64
67
 
65
- # Configure Columns parsing
68
+ # Enable Columns visualisation
66
69
  # default false
67
70
  config.columns = true
68
71
 
69
- # Configure Class Hierarchy parsing
72
+ # Enable Class Hierarchy visualisation
73
+ # default true
70
74
  config.inheritance = true
71
75
 
72
- # Configure Database entities
76
+ # Enable Databases visualisation
73
77
  # default true
74
- config.database = false
78
+ config.databases = false
75
79
 
76
- # Configure inclusion of Packwerk packages
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"
@@ -25,6 +26,7 @@ require_relative "./builders/associations"
25
26
  require_relative "./builders/models"
26
27
  require_relative "./builders/packs"
27
28
  require_relative "./builders/databases"
29
+ require_relative "./builders/gems_builder"
28
30
 
29
31
  module RailsGraph
30
32
  module Commands
@@ -36,10 +38,11 @@ module RailsGraph
36
38
  def call
37
39
  setup_generic_nodes
38
40
 
39
- RailsGraph::Commands::Builders::Databases.enrich(graph: graph) if configuration.databases?
41
+ RailsGraph::Commands::Builders::GemsBuilder.enrich(graph: graph, configuration: configuration)
42
+ RailsGraph::Commands::Builders::Databases.enrich(graph: graph, configuration: configuration)
40
43
  RailsGraph::Commands::Builders::Models.enrich(inspector: inspector, graph: graph, classes: classes,
41
44
  configuration: configuration)
42
- RailsGraph::Commands::Builders::Packs.enrich(graph: graph) if configuration.include_packwerk?
45
+ RailsGraph::Commands::Builders::Packs.enrich(graph: graph, configuration: configuration)
43
46
 
44
47
  graph
45
48
  end
@@ -4,7 +4,9 @@ module RailsGraph
4
4
  module Commands
5
5
  module Builders
6
6
  class Databases
7
- def self.enrich(graph:)
7
+ def self.enrich(graph:, configuration:)
8
+ return unless configuration.databases?
9
+
8
10
  new(graph: graph).enrich
9
11
 
10
12
  graph
@@ -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,7 +4,9 @@ module RailsGraph
4
4
  module Commands
5
5
  module Builders
6
6
  class Packs
7
- def self.enrich(graph:)
7
+ def self.enrich(graph:, configuration:)
8
+ return unless configuration.include_packwerk?
9
+
8
10
  new(graph: graph).enrich
9
11
 
10
12
  graph
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsGraph
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
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.3.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: 2023-05-29 00:00:00.000000000 Z
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.0.alpha.8
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.0.alpha.8
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
@@ -87,6 +75,7 @@ files:
87
75
  - lib/rails_graph/commands/build_graph.rb
88
76
  - lib/rails_graph/commands/builders/associations.rb
89
77
  - lib/rails_graph/commands/builders/databases.rb
78
+ - lib/rails_graph/commands/builders/gems_builder.rb
90
79
  - lib/rails_graph/commands/builders/models.rb
91
80
  - lib/rails_graph/commands/builders/packs.rb
92
81
  - lib/rails_graph/commands/export_graph.rb
@@ -102,6 +91,7 @@ files:
102
91
  - lib/rails_graph/graph/nodes/abstract_model.rb
103
92
  - lib/rails_graph/graph/nodes/column.rb
104
93
  - lib/rails_graph/graph/nodes/database.rb
94
+ - lib/rails_graph/graph/nodes/gem.rb
105
95
  - lib/rails_graph/graph/nodes/model.rb
106
96
  - lib/rails_graph/graph/nodes/pack.rb
107
97
  - lib/rails_graph/graph/nodes/table.rb
@@ -143,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
133
  - !ruby/object:Gem::Version
144
134
  version: '0'
145
135
  requirements: []
146
- rubygems_version: 3.3.7
136
+ rubygems_version: 3.4.19
147
137
  signing_key:
148
138
  specification_version: 4
149
139
  summary: Graph visualization for Rails applications.