deps_grapher 1.0.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 (60) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile +16 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +327 -0
  6. data/Rakefile +12 -0
  7. data/bin/console +15 -0
  8. data/bin/deps_grapher +96 -0
  9. data/bin/setup +8 -0
  10. data/deps_grapher.gemspec +34 -0
  11. data/lefthook.yml +14 -0
  12. data/lib/deps_grapher/ast_processor.rb +211 -0
  13. data/lib/deps_grapher/ast_processor_policy.rb +45 -0
  14. data/lib/deps_grapher/cache_file.rb +48 -0
  15. data/lib/deps_grapher/cli.rb +29 -0
  16. data/lib/deps_grapher/command/analyzer.rb +89 -0
  17. data/lib/deps_grapher/command/init.rb +49 -0
  18. data/lib/deps_grapher/configuration.rb +99 -0
  19. data/lib/deps_grapher/context.rb +48 -0
  20. data/lib/deps_grapher/cytoscape/cose.rb +36 -0
  21. data/lib/deps_grapher/cytoscape/fcose.rb +36 -0
  22. data/lib/deps_grapher/cytoscape/klay.rb +27 -0
  23. data/lib/deps_grapher/cytoscape/template.erb +61 -0
  24. data/lib/deps_grapher/cytoscape.rb +88 -0
  25. data/lib/deps_grapher/dsl.rb +50 -0
  26. data/lib/deps_grapher/edge.rb +58 -0
  27. data/lib/deps_grapher/errors.rb +8 -0
  28. data/lib/deps_grapher/event.rb +63 -0
  29. data/lib/deps_grapher/graph.rb +71 -0
  30. data/lib/deps_grapher/graphile/generator.rb +42 -0
  31. data/lib/deps_grapher/graphile/graphile.erb +119 -0
  32. data/lib/deps_grapher/graphile/graphile.temp.erb +23 -0
  33. data/lib/deps_grapher/html_writer.rb +16 -0
  34. data/lib/deps_grapher/input.rb +40 -0
  35. data/lib/deps_grapher/layer/registry.rb +32 -0
  36. data/lib/deps_grapher/layer.rb +75 -0
  37. data/lib/deps_grapher/logging.rb +21 -0
  38. data/lib/deps_grapher/matcher.rb +28 -0
  39. data/lib/deps_grapher/node.rb +65 -0
  40. data/lib/deps_grapher/plugin_dsl.rb +12 -0
  41. data/lib/deps_grapher/plugin_loader.rb +29 -0
  42. data/lib/deps_grapher/source.rb +51 -0
  43. data/lib/deps_grapher/source_cache/class_name_extractor.rb +60 -0
  44. data/lib/deps_grapher/source_cache/registry.rb +64 -0
  45. data/lib/deps_grapher/source_cache.rb +49 -0
  46. data/lib/deps_grapher/version.rb +5 -0
  47. data/lib/deps_grapher/vis/box.rb +21 -0
  48. data/lib/deps_grapher/vis/dot.rb +17 -0
  49. data/lib/deps_grapher/vis/template.erb +36 -0
  50. data/lib/deps_grapher/vis.rb +69 -0
  51. data/lib/deps_grapher/visualizer/base.rb +74 -0
  52. data/lib/deps_grapher/visualizer/color/registry.rb +30 -0
  53. data/lib/deps_grapher/visualizer/color.rb +62 -0
  54. data/lib/deps_grapher/visualizer/command_option.rb +22 -0
  55. data/lib/deps_grapher/visualizer/downloader.rb +42 -0
  56. data/lib/deps_grapher/visualizer/js_option.rb +39 -0
  57. data/lib/deps_grapher/visualizer/registry.rb +37 -0
  58. data/lib/deps_grapher/visualizer.rb +11 -0
  59. data/lib/deps_grapher.rb +42 -0
  60. metadata +135 -0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DepsGrapher
4
+ module Visualizer
5
+ class Color
6
+ module Registry
7
+ class << self
8
+ def fetch(layer_name)
9
+ registry.fetch layer_name
10
+ end
11
+ alias [] fetch
12
+
13
+ def register(layer_name, color)
14
+ registry[layer_name] = color
15
+ end
16
+
17
+ def all
18
+ registry.values
19
+ end
20
+
21
+ private
22
+
23
+ def registry
24
+ @registry ||= {}
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "color/registry"
4
+
5
+ module DepsGrapher
6
+ module Visualizer
7
+ class Color
8
+ class << self
9
+ def fetch(layer_name)
10
+ Registry.fetch layer_name
11
+ end
12
+ alias [] fetch
13
+
14
+ def generate_map(type)
15
+ Registry.all.to_h { |color| [color.layer_name, color.send(type)] }
16
+ end
17
+ end
18
+
19
+ attr_accessor :layer_name, :background, :border, :font, :arrow, :settings
20
+
21
+ def initialize(layer_name, &block)
22
+ DSL.new(self).instance_eval(&block)
23
+
24
+ @layer_name = layer_name
25
+ @font ||= "#fff"
26
+
27
+ assert!
28
+
29
+ @settings = {
30
+ background: background,
31
+ border: border,
32
+ font: font,
33
+ highlight: {
34
+ background: background,
35
+ border: border,
36
+ font: font
37
+ }
38
+ }
39
+
40
+ Registry.register layer_name, self
41
+ end
42
+
43
+ def highlight(background:, border:, font: "#fff")
44
+ @settings[:highlight] = {
45
+ background: background,
46
+ border: border,
47
+ font: font
48
+ }
49
+
50
+ self
51
+ end
52
+
53
+ private
54
+
55
+ def assert!
56
+ raise ArgumentError, "color: no `background` given" if background.blank?
57
+ raise ArgumentError, "color: no `border` given" if border.blank?
58
+ raise ArgumentError, "color: no `font` given" if font.blank?
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DepsGrapher
4
+ module Visualizer
5
+ class CommandOption
6
+ attr_reader :name
7
+
8
+ def initialize(name, default)
9
+ @name = name
10
+ @default = default
11
+ end
12
+
13
+ def default?
14
+ @default
15
+ end
16
+
17
+ def to_s
18
+ name
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DepsGrapher
4
+ module Visualizer
5
+ class Downloader
6
+ include Logging
7
+
8
+ def initialize(download_dir)
9
+ @download_dir = download_dir
10
+ end
11
+
12
+ def download(url, force: false)
13
+ uri = URI.parse url
14
+ file_name = File.basename uri.to_s
15
+ file_path = File.join @download_dir, file_name
16
+
17
+ FileUtils.rm_f file_path if force
18
+
19
+ return if File.exist?(file_path)
20
+
21
+ response = get_response uri
22
+
23
+ raise "download error occurred: #{uri} (#{response.code})" if response.code.to_i != 200
24
+
25
+ File.write file_path, response.body
26
+ end
27
+
28
+ private
29
+
30
+ def get_response(uri)
31
+ response = Net::HTTP.get_response uri
32
+ if response["location"]
33
+ uri.merge! response["location"]
34
+ verbose { "Follow redirect to #{uri} to download library" }
35
+ get_response uri
36
+ else
37
+ response
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DepsGrapher
4
+ module Visualizer
5
+ class JsOption
6
+ class Function
7
+ def initialize(body:, args: nil)
8
+ @args = args
9
+ @body = body
10
+ end
11
+
12
+ def as_json(*)
13
+ <<~JS.split(/$/).map(&:strip).compact_blank.join(";")
14
+ function(#{Array(@args).join(", ")}) {
15
+ #{@body}
16
+ }
17
+ JS
18
+ end
19
+ end
20
+
21
+ def initialize(hash = {})
22
+ @hash = hash
23
+ end
24
+
25
+ def add_function(name:, body:, args: nil)
26
+ @hash[name] = Function.new(args: args, body: body)
27
+ self
28
+ end
29
+
30
+ def as_json(*)
31
+ @hash.as_json
32
+ end
33
+
34
+ def to_s
35
+ as_json.to_json.gsub('"function', "function").gsub('}"', "}")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DepsGrapher
4
+ module Visualizer
5
+ module Registry
6
+ class << self
7
+ def fetch(key)
8
+ registry.fetch(key).first
9
+ end
10
+
11
+ def default_visualizer
12
+ command_options.find(&:default?).to_s
13
+ end
14
+
15
+ def available_visualizers
16
+ command_options.map(&:to_s)
17
+ end
18
+
19
+ def register(klass, command_option)
20
+ raise ArgumentError, "visualizer: `#{klass}` must be a subclass of `DepsGrapher::Visualizer::Base`" unless klass.ancestors.include?(Visualizer::Base)
21
+
22
+ registry[command_option.name] = [klass, command_option]
23
+ end
24
+
25
+ private
26
+
27
+ def command_options
28
+ registry.values.map { _2 }
29
+ end
30
+
31
+ def registry
32
+ @registry ||= {}
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DepsGrapher
4
+ module Visualizer
5
+ class << self
6
+ def fetch(name)
7
+ Registry.fetch name
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "active_support"
5
+ require "active_support/core_ext"
6
+ require "json"
7
+ require "fileutils"
8
+ require "parser/current"
9
+ require "net/https"
10
+ require "logger"
11
+ require "erb"
12
+ require "tempfile"
13
+ require "digest/md5"
14
+ require_relative "deps_grapher/version"
15
+ require_relative "deps_grapher/errors"
16
+ require_relative "deps_grapher/logging"
17
+ require_relative "deps_grapher/dsl"
18
+ require_relative "deps_grapher/plugin_dsl"
19
+
20
+ module DepsGrapher
21
+ class << self
22
+ def config
23
+ @config ||= Configuration.new
24
+ end
25
+
26
+ def configure
27
+ yield config
28
+ end
29
+
30
+ def logger
31
+ config.logger
32
+ end
33
+
34
+ def cache_file(key)
35
+ CacheFile.new(file: File.join(config.cache_dir, key.to_s), ttl: config.cache_ttl).tap do |cache_file|
36
+ cache_file.clean! force: config.clean
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ Dir.glob(File.expand_path(File.join("**", "*.rb"), __dir__)).sort.each { |f| require f }
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deps_grapher
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - jk-es335
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - dev@hacomono.co.jp
44
+ - soultraingang.dev@gmail.com
45
+ executables:
46
+ - deps_grapher
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/deps_grapher
57
+ - bin/setup
58
+ - deps_grapher.gemspec
59
+ - lefthook.yml
60
+ - lib/deps_grapher.rb
61
+ - lib/deps_grapher/ast_processor.rb
62
+ - lib/deps_grapher/ast_processor_policy.rb
63
+ - lib/deps_grapher/cache_file.rb
64
+ - lib/deps_grapher/cli.rb
65
+ - lib/deps_grapher/command/analyzer.rb
66
+ - lib/deps_grapher/command/init.rb
67
+ - lib/deps_grapher/configuration.rb
68
+ - lib/deps_grapher/context.rb
69
+ - lib/deps_grapher/cytoscape.rb
70
+ - lib/deps_grapher/cytoscape/cose.rb
71
+ - lib/deps_grapher/cytoscape/fcose.rb
72
+ - lib/deps_grapher/cytoscape/klay.rb
73
+ - lib/deps_grapher/cytoscape/template.erb
74
+ - lib/deps_grapher/dsl.rb
75
+ - lib/deps_grapher/edge.rb
76
+ - lib/deps_grapher/errors.rb
77
+ - lib/deps_grapher/event.rb
78
+ - lib/deps_grapher/graph.rb
79
+ - lib/deps_grapher/graphile/generator.rb
80
+ - lib/deps_grapher/graphile/graphile.erb
81
+ - lib/deps_grapher/graphile/graphile.temp.erb
82
+ - lib/deps_grapher/html_writer.rb
83
+ - lib/deps_grapher/input.rb
84
+ - lib/deps_grapher/layer.rb
85
+ - lib/deps_grapher/layer/registry.rb
86
+ - lib/deps_grapher/logging.rb
87
+ - lib/deps_grapher/matcher.rb
88
+ - lib/deps_grapher/node.rb
89
+ - lib/deps_grapher/plugin_dsl.rb
90
+ - lib/deps_grapher/plugin_loader.rb
91
+ - lib/deps_grapher/source.rb
92
+ - lib/deps_grapher/source_cache.rb
93
+ - lib/deps_grapher/source_cache/class_name_extractor.rb
94
+ - lib/deps_grapher/source_cache/registry.rb
95
+ - lib/deps_grapher/version.rb
96
+ - lib/deps_grapher/vis.rb
97
+ - lib/deps_grapher/vis/box.rb
98
+ - lib/deps_grapher/vis/dot.rb
99
+ - lib/deps_grapher/vis/template.erb
100
+ - lib/deps_grapher/visualizer.rb
101
+ - lib/deps_grapher/visualizer/base.rb
102
+ - lib/deps_grapher/visualizer/color.rb
103
+ - lib/deps_grapher/visualizer/color/registry.rb
104
+ - lib/deps_grapher/visualizer/command_option.rb
105
+ - lib/deps_grapher/visualizer/downloader.rb
106
+ - lib/deps_grapher/visualizer/js_option.rb
107
+ - lib/deps_grapher/visualizer/registry.rb
108
+ homepage: https://github.com/hacomono-lib/deps_grapher
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ rubygems_mfa_required: 'true'
113
+ homepage_uri: https://github.com/hacomono-lib/deps_grapher
114
+ source_code_uri: https://github.com/hacomono-lib/deps_grapher
115
+ changelog_uri: https://github.com/hacomono-lib/deps_grapher
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '2.7'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubygems_version: 3.5.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Tool to visualize Ruby class dependencies
135
+ test_files: []