Class: Pocky::Packwerk

Inherits:
Object
  • Object
show all
Defined in:
lib/pocky/packwerk.rb

Constant Summary collapse

MAX_EDGE_WIDTH =
5

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_path: nil, default_package: 'root', filename: 'packwerk.png', analyze_sizes: false, dpi: 100, package_color: '#5CC8FF', secondary_package_color: '#AAAAAA', dependency_edge: 'darkgreen', deprecated_reference_edge: 'black', deprecated_reference_ranking: true) ⇒ Packwerk



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pocky/packwerk.rb', line 15

def initialize(
  package_path: nil,
  default_package: 'root',
  filename: 'packwerk.png',
  analyze_sizes: false,
  dpi: 100,
  package_color: '#5CC8FF',
  secondary_package_color: '#AAAAAA',
  dependency_edge: 'darkgreen',
  deprecated_reference_edge: 'black',
  deprecated_reference_ranking: true
)
  @package_paths = [*package_path] if package_path
  @root_path = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)

  @default_package = default_package
  @filename = filename
  @analyze_sizes = analyze_sizes
  @dpi = dpi.to_i
  @secondary_package_color = secondary_package_color

  @nodes = {}

  @node_options = {
    fontsize: 26.0,
    fontcolor: 'white',
    fillcolor: package_color,
    color: package_color,
    height: 1.0,
    style: 'filled, rounded',
    shape: 'box'
  }

  @dependency_edge_options = {
    color: dependency_edge
  }

  @deprecated_references_edge_options = {
    color: deprecated_reference_edge,
  }
  @deprecated_references_edge_options.merge!(constraint: false) unless deprecated_reference_ranking
end

Class Method Details

.generate(params = {}) ⇒ Object



10
11
12
# File 'lib/pocky/packwerk.rb', line 10

def self.generate(params = {})
  new(**params).generate
end

Instance Method Details

#generateObject



58
59
60
61
62
# File 'lib/pocky/packwerk.rb', line 58

def generate
  @graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
  draw_packages
  @graph.output(png: @filename)
end