pocky 2.5.0 → 2.6.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: 608e94e135cd12c4340c3b9b1987a0c8af537784
4
- data.tar.gz: b2a786abb2378189cfd332d9a751c019c7efe5bd
3
+ metadata.gz: de11dcff9a0765101df1f14137880873958a8049
4
+ data.tar.gz: 17ee8cd45457cf323bc2edc65fa97863798825ca
5
5
  SHA512:
6
- metadata.gz: dacdbddb1d69b2920202123a43768b87329740b2a82758f84a44cdce37d613a4f102ca440754bffce504198cf40b6976bf5807046047286152b956952211c9ff
7
- data.tar.gz: dfc30c35e7a3ba4223f76c55e4466ccf1172e3631affa7a9a0e67375194289d08f1416218541147265fde427078da3580becd1a52ec5f201eff0daa7184ce8ba
6
+ metadata.gz: 36777289020339a7899b4d830e7dea1b3d2b4c693df77c9419c9468e358cf068343a83d872ab99d41d6989c1961041c27e05d7cb8d7a25d591f0aa26fcc99f7a
7
+ data.tar.gz: d68f933f49969f5c375614aea01c8f40d7802a9a90cd2fac8d8f4c789bbacf217a98c547400883baaed98f0a971b83e3bc2cf83693d23c382b76b45be5a25e93
data/lib/pocky.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'pocky/version'
4
4
  require_relative 'pocky/ruby_file_size'
5
+ require_relative 'pocky/package'
5
6
  require_relative 'pocky/packwerk'
6
7
 
7
8
  module Pocky
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Pocky
6
+ class Package
7
+ attr_reader :name, :dependencies, :enforce_privacy, :deprecated_references
8
+
9
+ def initialize(name:, filename: nil)
10
+ @name = name
11
+ @filename = filename
12
+ @dependencies = yml['dependencies'] || []
13
+ @enforce_privacy = yml['enforce_privacy'] || false
14
+ @deprecated_references = {}
15
+ end
16
+
17
+ def add_deprecated_references(reference_filename)
18
+ @deprecated_references = YAML.load_file(reference_filename) || {}
19
+ end
20
+
21
+ private
22
+
23
+ def yml
24
+ @yml ||= begin
25
+ if @filename
26
+ YAML.load_file(@filename) || {}
27
+ else
28
+ {}
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
- require 'yaml'
5
4
  require 'ruby-graphviz'
6
5
 
7
6
  module Pocky
8
- class InvalidRootPathError < StandardError
9
- end
10
-
11
7
  class Packwerk
12
8
  DEPENDENCIES_FILENAME = 'package.yml'
13
9
  DEPRECATED_REFERENCES_FILENAME = 'deprecated_references.yml'
@@ -35,10 +31,9 @@ module Pocky
35
31
  @default_package = default_package
36
32
  @filename = filename
37
33
  @analyze_sizes = analyze_sizes
38
-
39
34
  @dpi = dpi.to_i
40
- @deprecated_references = {}
41
- @package_dependencies = {}
35
+
36
+ @packages = {}
42
37
  @nodes = {}
43
38
 
44
39
  @node_options = {
@@ -73,54 +68,57 @@ module Pocky
73
68
  if file_size < 10
74
69
  { fontsize: 26 }
75
70
  elsif file_size < 100
76
- { fontsize: 26 * 4, margin: 0.2 }
71
+ { fontsize: 26 * 2, margin: 0.2 }
77
72
  elsif file_size < 1000
78
- { fontsize: 26 * 8, margin: 0.4 }
73
+ { fontsize: 26 * 4, margin: 0.4 }
79
74
  elsif file_size < 10_000
80
- { fontsize: 26 * 16, margin: 0.8 }
75
+ { fontsize: 26 * 8, margin: 0.8 }
81
76
  else
82
- { fontsize: 26 * 32, margin: 1.0 }
77
+ { fontsize: 26 * 16, margin: 1.0 }
83
78
  end
84
79
  end
85
80
 
86
81
  def draw_node(package)
87
- package_name = package_name_for_dependency(package)
88
- path = package == '.' ? @root_path : @root_path.join(package)
82
+ package_name = package_name_for_dependency(package.name)
83
+ path = package.name == '.' ? @root_path : @root_path.join(package.name)
89
84
  file_size = @analyze_sizes ? RubyFileSize.compute(path.to_s) : 1
90
- @graph.add_nodes(package_name, **@node_options.merge(node_overrides(file_size)))
85
+ node_label = "#{package_name}#{' (Þ)' if package.enforce_privacy}"
86
+
87
+ @graph.add_nodes(
88
+ package_name,
89
+ **@node_options.merge(
90
+ **node_overrides(file_size),
91
+ label: node_label
92
+ )
93
+ )
91
94
  end
92
95
 
93
96
  def build_directed_graph
94
97
  @graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
95
- draw_dependencies
96
- draw_deprecated_references
98
+ draw_packages
97
99
  @graph.output(png: @filename)
98
100
  end
99
101
 
100
- def draw_dependencies
101
- @package_dependencies.each do |package, file|
102
- @nodes[package] ||= draw_node(package)
103
- file.each do |provider|
104
- @nodes[provider] ||= draw_node(provider)
102
+ def draw_packages
103
+ @packages.each do |_name, package|
104
+ @nodes[package.name] ||= draw_node(package)
105
+
106
+ package.dependencies.each do |dependency|
107
+ @nodes[dependency] ||= draw_node(@packages[dependency])
105
108
 
106
109
  @graph.add_edges(
107
- @nodes[package],
108
- @nodes[provider],
110
+ @nodes[package.name],
111
+ @nodes[dependency],
109
112
  **@dependency_edge_options
110
113
  )
111
114
  end
112
- end
113
- end
114
115
 
115
- def draw_deprecated_references
116
- @deprecated_references.each do |package, references|
117
- @nodes[package] ||= draw_node(package)
118
- references.each do |provider, invocations|
119
- @nodes[provider] ||= draw_node(provider)
116
+ package.deprecated_references.each do |provider_name, invocations|
117
+ @nodes[provider_name] ||= draw_node(@packages[provider_name])
120
118
 
121
119
  @graph.add_edges(
122
- @nodes[package],
123
- @nodes[provider],
120
+ @nodes[package.name],
121
+ @nodes[provider_name],
124
122
  **@deprecated_references_edge_options.merge(
125
123
  penwidth: edge_width(invocations.length),
126
124
  ),
@@ -160,11 +158,8 @@ module Pocky
160
158
  return if dependencies_files.empty?
161
159
 
162
160
  dependencies_files.each do |filename|
163
- package = parse_package_name(filename)
164
- @package_dependencies[package] ||= begin
165
- yml = YAML.load_file(filename) || {}
166
- yml['dependencies'] || []
167
- end
161
+ package_name = parse_package_name(filename)
162
+ @packages[package_name] ||= Pocky::Package.new(name: package_name, filename: filename)
168
163
  end
169
164
  end
170
165
 
@@ -172,14 +167,20 @@ module Pocky
172
167
  return if deprecated_references_files.empty?
173
168
 
174
169
  deprecated_references_files.each do |filename|
175
- package = parse_package_name(filename)
176
- @deprecated_references[package] ||= YAML.load_file(filename) || {}
170
+ package_name = parse_package_name(filename)
171
+ @packages[package_name] ||= Pocky::Package.new(name: package_name)
172
+ @packages[package_name].add_deprecated_references(filename)
173
+
174
+ # Walk the references to create referenced packages
175
+ @packages[package_name].deprecated_references.each do |provider_name, _violations|
176
+ @packages[provider_name] ||= Pocky::Package.new(name: provider_name)
177
+ end
177
178
  end
178
179
  end
179
180
 
180
181
  def parse_package_name(filename)
181
182
  name = File.dirname(filename).gsub(@root_path.to_s, '')
182
- name == '' ? @default_package : name.gsub(/^\//, '')
183
+ name == '' ? '.' : name.gsub(/^\//, '')
183
184
  end
184
185
 
185
186
  def package_name_for_dependency(name)
data/lib/pocky/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pocky
4
- VERSION = "2.5.0"
4
+ VERSION = "2.6.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.5.0
4
+ version: 2.6.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-02-02 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-graphviz
@@ -42,6 +42,7 @@ files:
42
42
  - bin/setup
43
43
  - lib/pocky.rb
44
44
  - lib/pocky/Rakefile
45
+ - lib/pocky/package.rb
45
46
  - lib/pocky/packwerk.rb
46
47
  - lib/pocky/railtie.rb
47
48
  - lib/pocky/ruby_file_size.rb