pocky 2.3.0 → 2.4.0

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
  SHA1:
3
- metadata.gz: bf6db66f143fca23ba7dd902fc5af98d3d664972
4
- data.tar.gz: a7acc183fe0d502d6a4a48b5866617a335c4b6ba
3
+ metadata.gz: ec4633fc47cd55e4bb54ea0378567ebaa792ed20
4
+ data.tar.gz: 0ff1ee4a69d65d586440ed2287958370ff2edc7f
5
5
  SHA512:
6
- metadata.gz: 05e7cc845b387c26c5a65c2d3503d5080b807ee61328538cd267680546d7b32cbdbbebb14327560bdbad2a9927c4552ce5281b75f105e564922a89b6c0f105a8
7
- data.tar.gz: d2aebfb4e4f70e8e5b90925825d082acf5ade98b85e8d5cf81c46d4b5d3733845bdf5c2364c5a44fe196e8cb6146acb400cfc652241d3746c727ec5e83331cee
6
+ metadata.gz: 17398615fbe7d3b8ac88ac5fd3a36844b417f998d7aea02a6d8f361f5af8402dac03284e091d1a8e2a2776f48a89b1e5f1c8fbef7fefe51681034ebfa82e1331
7
+ data.tar.gz: 94517f49a5813913ecc8d29dcdbf8f6e6a1847a741dcb622d4b7ae10c6d14565a8da62ff8b16072de3f6018be13a57c7794cd23ed8c5f920bfc1dd6b82d52604
@@ -8,19 +8,32 @@ module Pocky
8
8
  class InvalidRootPathError < StandardError
9
9
  end
10
10
 
11
+ class RubyFileSize
12
+ def self.compute(directory)
13
+ # Sum up all ruby source except for specs
14
+ package_size = Dir[File.join(directory, '**', '*.rb').to_s].reduce(0) do |size, filename|
15
+ size += File.size(filename) unless filename.match(/spec\.rb$/)
16
+ size
17
+ end
18
+
19
+ # to kB
20
+ (package_size / 1024).ceil
21
+ end
22
+ end
23
+
11
24
  class Packwerk
12
25
  DEPENDENCIES_FILENAME = 'package.yml'
13
26
  DEPRECATED_REFERENCES_FILENAME = 'deprecated_references.yml'
14
27
  MAX_EDGE_WIDTH = 5
15
28
 
16
- def self.generate(params)
29
+ def self.generate(params = {})
17
30
  new(**params).generate
18
31
  end
19
32
 
20
33
  private_class_method :new
21
34
  def initialize(
22
35
  package_path: nil,
23
- default_package: 'app',
36
+ default_package: 'root',
24
37
  filename: 'packwerk.png',
25
38
  dpi: 100,
26
39
  package_color: '#5CC8FF',
@@ -45,8 +58,9 @@ module Pocky
45
58
  color: package_color,
46
59
  height: 1.0,
47
60
  style: 'filled, rounded',
48
- shape: 'box',
61
+ shape: 'box'
49
62
  }
63
+
50
64
  @dependency_edge_options = {
51
65
  color: dependency_edge
52
66
  }
@@ -65,6 +79,27 @@ module Pocky
65
79
 
66
80
  private
67
81
 
82
+ def node_overrides(file_size)
83
+ if file_size < 10
84
+ { fontsize: 26 }
85
+ elsif file_size < 100
86
+ { fontsize: 26 * 4, margin: 0.2 }
87
+ elsif file_size < 1000
88
+ { fontsize: 26 * 8, margin: 0.4 }
89
+ elsif file_size < 10_000
90
+ { fontsize: 26 * 16, margin: 0.8 }
91
+ else
92
+ { fontsize: 26 * 32, margin: 1.0 }
93
+ end
94
+ end
95
+
96
+ def draw_node(package)
97
+ package_name = package_name_for_dependency(package)
98
+ path = package == '.' ? @root_path : @root_path.join(package)
99
+ file_size = RubyFileSize.compute(path.to_s)
100
+ @graph.add_nodes(package_name, **@node_options.merge(node_overrides(file_size)))
101
+ end
102
+
68
103
  def build_directed_graph
69
104
  @graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
70
105
  draw_dependencies
@@ -74,14 +109,13 @@ module Pocky
74
109
 
75
110
  def draw_dependencies
76
111
  @package_dependencies.each do |package, file|
77
- @nodes[package] ||= @graph.add_nodes(package, **@node_options)
112
+ @nodes[package] ||= draw_node(package)
78
113
  file.each do |provider|
79
- provider_package = package_name_for_dependency(provider)
80
- @nodes[provider_package] ||= @graph.add_nodes(provider_package, **@node_options)
114
+ @nodes[provider] ||= draw_node(provider)
81
115
 
82
116
  @graph.add_edges(
83
117
  @nodes[package],
84
- @nodes[provider_package],
118
+ @nodes[provider],
85
119
  **@dependency_edge_options
86
120
  )
87
121
  end
@@ -90,14 +124,13 @@ module Pocky
90
124
 
91
125
  def draw_deprecated_references
92
126
  @deprecated_references.each do |package, references|
93
- @nodes[package] ||= @graph.add_nodes(package, **@node_options)
127
+ @nodes[package] ||= draw_node(package)
94
128
  references.each do |provider, invocations|
95
- provider_package = package_name_for_dependency(provider)
96
- @nodes[provider_package] ||= @graph.add_nodes(provider_package, **@node_options)
129
+ @nodes[provider] ||= draw_node(provider)
97
130
 
98
131
  @graph.add_edges(
99
132
  @nodes[package],
100
- @nodes[provider_package],
133
+ @nodes[provider],
101
134
  **@deprecated_references_edge_options.merge(
102
135
  penwidth: edge_width(invocations.length),
103
136
  ),
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pocky
4
- VERSION = "2.3.0"
4
+ VERSION = "2.4.0"
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: 2.3.0
4
+ version: 2.4.0
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-26 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-graphviz