pocky 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a33d7a33b47a8ec7b5763188f1670934db2b63df6e16409371ec10456a06ff98
4
- data.tar.gz: afe4ed9619ec1d6843fb23a92fde8ef89349650fec21abc2e584cccdd7ba9096
3
+ metadata.gz: ab45111779ec64a861557a7efeb7fefb02a255e0aa34ab791b8ae747475e7614
4
+ data.tar.gz: e9b23a9174780956f67ab1db2746050e94649b7a56243b8a201598e18cb49181
5
5
  SHA512:
6
- metadata.gz: 2469169116f8afcebfd1fd41e05b6a74526c37e4abcdd78b94feae73867773fcc277192a6e8ea89ac57f35ce4608d9ec657e4b7309e59875bd11b0eb40b6bfa3
7
- data.tar.gz: 6ef340611027d6ffea6044c1f03576d5b78ea1b70b2d852a9a1784c99d66d644abd07c4c71ccf58f9edeb98b7dbe42c3cb7eb2867afcc5fdf1a0ed60b692ded2
6
+ metadata.gz: 29bcf083442dfe4e2267b8475fcc872a90161f6ee9a0bc4321fec130acfaad2598557ebd2084ef106ea41887a9d86de9e35c36e2c73b74690c2b4bd1f567a3ca
7
+ data.tar.gz: c843b24dcc15b025d7426821abfd58da27dcfdef877752e75c53b6750dce4783a618ba7a1df0125658888c6b1c688ef8fe1cd35b82a5fab522e25d754ebde013
data/README.md CHANGED
@@ -10,9 +10,9 @@ Invoke from irb or code, only `root_path` is required.
10
10
  ```ruby
11
11
  Pocky::Packwerk.generate(
12
12
  root_path: 'path/to/app/packages',
13
- default_package: 'Default', # The default package listed as "." in deprecated_references.yml
13
+ default_package: 'app', # The default package listed as "." in deprecated_references.yml
14
14
  filename: 'packwerk-viz.png', # Name of output file
15
- dpi: 150 # Output file resolution
15
+ dpi: 100 # Output file resolution
16
16
  )
17
17
  ```
18
18
 
@@ -8,7 +8,8 @@ module Pocky
8
8
  end
9
9
 
10
10
  class Packwerk
11
- REFERENCE_FILE_NAME = 'deprecated_references.yml'
11
+ DEPENDENCIES_FILENAME = 'package.yml'
12
+ DEPRECATED_REFERENCES_FILENAME = 'deprecated_references.yml'
12
13
  MAX_EDGE_WIDTH = 5
13
14
 
14
15
  def self.generate(params)
@@ -18,9 +19,9 @@ module Pocky
18
19
  private_class_method :new
19
20
  def initialize(
20
21
  root_path:,
21
- default_package: 'Default',
22
+ default_package: 'app',
22
23
  filename: 'packwerk-viz.png',
23
- dpi: 150
24
+ dpi: 100
24
25
  )
25
26
  @root_paths = [*root_path]
26
27
  raise InvalidRootPathError, 'root_path is required' if @root_paths.empty?
@@ -29,33 +30,54 @@ module Pocky
29
30
  @filename = filename
30
31
  @dpi = dpi.to_i
31
32
  @deprecated_references = {}
33
+ @package_dependencies = {}
32
34
  @nodes = {}
33
35
  end
34
36
 
35
37
  def generate
36
- load_package_references
38
+ load_dependencies
39
+ load_deprecated_references
37
40
  build_directed_graph
38
41
  end
39
42
 
40
43
  private
41
44
 
42
45
  def build_directed_graph
43
- graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
46
+ @graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
47
+ draw_dependencies
48
+ draw_deprecated_references
49
+ @graph.output(png: @filename)
50
+ end
51
+
52
+ def draw_dependencies
53
+ @package_dependencies.each do |package, file|
54
+ @nodes[package] ||= @graph.add_nodes(package)
55
+ file['dependencies'].each do |provider|
56
+ provider_package = package_name_for_dependency(provider)
57
+ @nodes[provider_package] ||= @graph.add_nodes(provider_package)
58
+
59
+ @graph.add_edges(
60
+ @nodes[package],
61
+ @nodes[provider_package]
62
+ )
63
+ end
64
+ end
65
+ end
66
+
67
+ def draw_deprecated_references
44
68
  @deprecated_references.each do |package, references|
45
- @nodes[package] ||= graph.add_nodes(package)
46
- references.each do |provider, dependencies|
69
+ @nodes[package] ||= @graph.add_nodes(package)
70
+ references.each do |provider, invocations|
47
71
  provider_package = package_name_for_dependency(provider)
48
- @nodes[provider_package] ||= graph.add_nodes(provider_package)
72
+ @nodes[provider_package] ||= @graph.add_nodes(provider_package)
49
73
 
50
- graph.add_edges(
74
+ @graph.add_edges(
51
75
  @nodes[package],
52
76
  @nodes[provider_package],
53
- penwidth: edge_width(dependencies.length)
77
+ pendwidth: edge_width(invocations.length)
54
78
  )
55
79
  end
56
80
  end
57
-
58
- graph.output(png: @filename)
59
81
  end
60
82
 
61
83
  def edge_width(count)
@@ -65,18 +87,31 @@ module Pocky
65
87
  ].min
66
88
  end
67
89
 
68
- def package_references
69
- @package_references ||= @root_paths.flat_map do |path|
70
- Dir["#{path}/**/#{REFERENCE_FILE_NAME}"]
90
+ def deprecated_references_files
91
+ @deprecated_references_files ||= @root_paths.flat_map do |path|
92
+ Dir["#{path}/**/#{DEPRECATED_REFERENCES_FILENAME}"]
71
93
  end
72
94
  end
73
95
 
74
- def load_package_references
75
- if package_references.empty?
76
- raise InvalidRootPathError, "Cannot find any #{REFERENCE_FILE_NAME} in provided root_path"
96
+ def dependencies_files
97
+ @dependencies_files ||= @root_paths.flat_map do |path|
98
+ Dir["#{path}/**/#{DEPENDENCIES_FILENAME}"]
77
99
  end
100
+ end
101
+
102
+ def load_dependencies
103
+ return if dependencies_files.empty?
104
+
105
+ dependencies_files.each do |filename|
106
+ package = parse_package_name(filename)
107
+ @package_dependencies[package] ||= YAML.load_file(filename) || {}
108
+ end
109
+ end
110
+
111
+ def load_deprecated_references
112
+ return if deprecated_references_files.empty?
78
113
 
79
- package_references.each do |filename|
114
+ deprecated_references_files.each do |filename|
80
115
  package = parse_package_name(filename)
81
116
  @deprecated_references[package] ||= YAML.load_file(filename) || {}
82
117
  end
@@ -89,7 +124,7 @@ module Pocky
89
124
  def package_name_for_dependency(name)
90
125
  return @default_package if name == '.'
91
126
 
92
- reference_filename = package_references.find do |ref|
127
+ reference_filename = deprecated_references.find do |ref|
93
128
  ref.match(/#{name}\/#{REFERENCE_FILE_NAME}$/)
94
129
  end
95
130
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pocky
4
- VERSION = "1.9.0"
4
+ VERSION = "1.9.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pocky
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quan Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-04 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-graphviz