rails_graph 0.1.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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +17 -0
  4. data/.ruby-version +1 -0
  5. data/.tool-versions +1 -0
  6. data/CHANGELOG.md +5 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +12 -0
  9. data/Gemfile.lock +142 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +89 -0
  12. data/Rakefile +12 -0
  13. data/graph.svg +1 -0
  14. data/lib/rails_graph/commands/build_graph.rb +113 -0
  15. data/lib/rails_graph/commands/export_graph.rb +21 -0
  16. data/lib/rails_graph/configuration.rb +26 -0
  17. data/lib/rails_graph/error.rb +5 -0
  18. data/lib/rails_graph/exporters/base.rb +7 -0
  19. data/lib/rails_graph/exporters/cypher.rb +62 -0
  20. data/lib/rails_graph/exporters/json.rb +16 -0
  21. data/lib/rails_graph/exporters/neo4j.rb +26 -0
  22. data/lib/rails_graph/graph/entity.rb +21 -0
  23. data/lib/rails_graph/graph/graph.rb +43 -0
  24. data/lib/rails_graph/graph/node.rb +26 -0
  25. data/lib/rails_graph/graph/nodes/abstract_model.rb +27 -0
  26. data/lib/rails_graph/graph/nodes/column.rb +31 -0
  27. data/lib/rails_graph/graph/nodes/model.rb +44 -0
  28. data/lib/rails_graph/graph/nodes/virtual_model.rb +23 -0
  29. data/lib/rails_graph/graph/relationship.rb +34 -0
  30. data/lib/rails_graph/graph/relationships/association.rb +74 -0
  31. data/lib/rails_graph/graph/relationships/attribute.rb +23 -0
  32. data/lib/rails_graph/graph/relationships/inheritance.rb +21 -0
  33. data/lib/rails_graph/helpers/associations.rb +31 -0
  34. data/lib/rails_graph/helpers/models.rb +13 -0
  35. data/lib/rails_graph/helpers/options_parser.rb +21 -0
  36. data/lib/rails_graph/railtie.rb +14 -0
  37. data/lib/rails_graph/tasks/rails_graph.rake +27 -0
  38. data/lib/rails_graph/version.rb +5 -0
  39. data/lib/rails_graph.rb +33 -0
  40. data/sig/rails_graph.rbs +4 -0
  41. metadata +140 -0
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsGraph
4
+ module Helpers
5
+ module Models
6
+ module_function
7
+
8
+ def identifier(model)
9
+ model.to_s.delete_prefix("::")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+
5
+ module RailsGraph
6
+ module Helpers
7
+ module OptionsParser
8
+ def parse_options(banner, arguments)
9
+ parser = OptionParser.new
10
+ parser.banner = banner
11
+ options = {}
12
+
13
+ arguments.each { |argument| parser.on(*argument) }
14
+
15
+ parser.parse!(parser.order!(ARGV), into: options)
16
+
17
+ options
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+
5
+ module RailsGraph
6
+ class Railtie < ::Rails::Railtie
7
+ railtie_name :rails_graph
8
+
9
+ rake_tasks do
10
+ path = File.expand_path(__dir__)
11
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../helpers/options_parser"
4
+
5
+ namespace :rails_graph do
6
+ include RailsGraph::Helpers::OptionsParser
7
+
8
+ namespace :export do
9
+ desc "Export graph to Neo4j graph database"
10
+ task neo4j: :environment do
11
+ options = parse_options(
12
+ "Usage: rails rails_graph:export:neo4j [options]",
13
+ [
14
+ ["-h", "--host HOST", "Neo4j host, e.g neo4j://localhost:7687"],
15
+ ["-u", "--username USERNAME", "Neo4j username"],
16
+ ["-p", "--password PASSWORD", "Neo4j password"]
17
+ ]
18
+ )
19
+
20
+ RailsGraph.load_entities
21
+ graph = RailsGraph.build_graph
22
+ RailsGraph.export_graph(graph: graph, format: :neo4j, **options)
23
+
24
+ exit
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsGraph
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_graph/version"
4
+ require "rails_graph/error"
5
+ require "rails_graph/configuration"
6
+ require "rails_graph/railtie"
7
+
8
+ require "rails_graph/commands/build_graph"
9
+ require "rails_graph/commands/export_graph"
10
+
11
+ module RailsGraph
12
+ module_function
13
+
14
+ def load_entities
15
+ Rails.application.eager_load!
16
+ end
17
+
18
+ def build_graph(configuration: nil)
19
+ Commands::BuildGraph.call(configuration: configuration || RailsGraph.configuration)
20
+ end
21
+
22
+ def export_graph(graph:, **opts)
23
+ Commands::ExportGraph.call(graph: graph, **opts)
24
+ end
25
+
26
+ def configuration
27
+ @configuration ||= Configuration.new
28
+ end
29
+
30
+ def configure
31
+ yield configuration if block_given?
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module RailsGraph
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahmad Elassuty
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '6.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: neo4j-ruby-driver
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 4.4.0.alpha.8
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 4.4.0.alpha.8
47
+ - !ruby/object:Gem::Dependency
48
+ name: railties
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '6.0'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '7.1'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '6.0'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '7.1'
67
+ description:
68
+ email:
69
+ - ahmad.elassuty@gmail.com
70
+ executables: []
71
+ extensions: []
72
+ extra_rdoc_files: []
73
+ files:
74
+ - ".rspec"
75
+ - ".rubocop.yml"
76
+ - ".ruby-version"
77
+ - ".tool-versions"
78
+ - CHANGELOG.md
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - graph.svg
86
+ - lib/rails_graph.rb
87
+ - lib/rails_graph/commands/build_graph.rb
88
+ - lib/rails_graph/commands/export_graph.rb
89
+ - lib/rails_graph/configuration.rb
90
+ - lib/rails_graph/error.rb
91
+ - lib/rails_graph/exporters/base.rb
92
+ - lib/rails_graph/exporters/cypher.rb
93
+ - lib/rails_graph/exporters/json.rb
94
+ - lib/rails_graph/exporters/neo4j.rb
95
+ - lib/rails_graph/graph/entity.rb
96
+ - lib/rails_graph/graph/graph.rb
97
+ - lib/rails_graph/graph/node.rb
98
+ - lib/rails_graph/graph/nodes/abstract_model.rb
99
+ - lib/rails_graph/graph/nodes/column.rb
100
+ - lib/rails_graph/graph/nodes/model.rb
101
+ - lib/rails_graph/graph/nodes/virtual_model.rb
102
+ - lib/rails_graph/graph/relationship.rb
103
+ - lib/rails_graph/graph/relationships/association.rb
104
+ - lib/rails_graph/graph/relationships/attribute.rb
105
+ - lib/rails_graph/graph/relationships/inheritance.rb
106
+ - lib/rails_graph/helpers/associations.rb
107
+ - lib/rails_graph/helpers/models.rb
108
+ - lib/rails_graph/helpers/options_parser.rb
109
+ - lib/rails_graph/railtie.rb
110
+ - lib/rails_graph/tasks/rails_graph.rake
111
+ - lib/rails_graph/version.rb
112
+ - sig/rails_graph.rbs
113
+ homepage: https://github.com/ahmad-elassuty/rails_graph
114
+ licenses:
115
+ - MIT
116
+ metadata:
117
+ rubygems_mfa_required: 'true'
118
+ homepage_uri: https://github.com/ahmad-elassuty/rails_graph
119
+ source_code_uri: https://github.com/ahmad-elassuty/rails_graph
120
+ changelog_uri: https://github.com/ahmad-elassuty/rails_graph/blob/main/CHANGELOG.md
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '3.0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.3.7
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Graph visualization for Rails applications.
140
+ test_files: []