graphwerk 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: 5d3fb33710355e47f3bbfaa7c9f78e01547cad92a379d0d449e9f9e4b9f2be5a
4
- data.tar.gz: 16c12353022a3b87bc1aae310fddbb176b0d4718ac7a85a33b17672d3ed1edab
3
+ metadata.gz: bf78a60a25721799a4c6dc0623fa3678ceead0369974a26a7828ce05b10a81e6
4
+ data.tar.gz: 877ded46de6dd8a16320e0eca0b0bf4f9cd1bed69e70aaf28b6b37057d25cb8d
5
5
  SHA512:
6
- metadata.gz: ca38ee1799a0c4bb6fc08ed41836c6773d80c2ffbb86333baedbcd390ac390866a9d4bb416282a06dba7d8e3520ac33d5089c6aa6814159479995c74c4fb12b1
7
- data.tar.gz: ca18e12ca29229fd82aaa316bd24bf40053fac581e3c25be1a71649c58498ecab3b131087183d54aa125f7348e03916c2352d71712fd2d374073eb616628983e
6
+ metadata.gz: 7f0abf8f377d771f2bd7fee6abc0d9872187493cca876b7ebea34511df1ef47b8c7c976f14d6b9671f9e5ad7a0fd3d6bef0aca56a3b199946fdfe73aedc5b009
7
+ data.tar.gz: be181ec7c607241974d2753cc0bc649a10d880624316a674e671b43bad259e8e56658d886486fb35970766dea95280eb8bfd209138af605da0ad64be299b6e36
@@ -1,3 +1,8 @@
1
+ 1.1.0
2
+
3
+ * Default layout switched to Dot
4
+ * Fixed a bug when running on an application where packages depend on the root package
5
+
1
6
  1.0.0
2
7
 
3
8
  * Initial release
data/README.md CHANGED
@@ -8,13 +8,13 @@ The gem builds on top of [Packwerk](https://github.com/Shopify/packwerk) and [Gr
8
8
 
9
9
  Here's an example application package dependency diagram:
10
10
 
11
- ![example](https://user-images.githubusercontent.com/2643026/95458900-c159c000-096a-11eb-86b7-b5ef7c1e936d.png)
11
+ ![example](https://user-images.githubusercontent.com/2643026/97689408-6ca1f480-1a93-11eb-9999-22e79791b300.png)
12
12
 
13
13
  ## Install
14
14
 
15
15
  Add this line to your application's Gemfile and run `bundle install`:
16
16
 
17
- `gem 'graphwerk'`
17
+ `gem 'graphwerk', group: %i[development test]`
18
18
 
19
19
  ## Usage
20
20
 
@@ -24,7 +24,7 @@ For Rails applications a Railtie automatically loads a rake task that makes it e
24
24
  bundle exec rake graphwerk:update
25
25
  ```
26
26
 
27
- More advance usage is possible by passing a `Packwerk::PackageSet` directly to `Graphwerk::Builders::Graph` and calling `#build` returning a `Graphviz` instance:
27
+ More advance usage is possible by passing a [`Packwerk::PackageSet`](https://github.com/Shopify/packwerk/blob/main/lib/packwerk/package_set.rb) directly to `Graphwerk::Builders::Graph` and calling `#build` returning a `Graphviz` instance:
28
28
 
29
29
  ```ruby
30
30
  graph = Graphwerk::Builders::Graph.new(
@@ -33,7 +33,7 @@ graph = Graphwerk::Builders::Graph.new(
33
33
  graph.output(svg: 'packwerk.svg')
34
34
  ```
35
35
 
36
- All Graphviz layouts are supported and options for the graph, nodes and edges can be set via an optional `options` argument:
36
+ All [Graphviz layouts](https://graphviz.org/documentation/#layout-manual-pages) are supported and options for the graph, nodes and edges can be set via an optional `options` argument:
37
37
 
38
38
  ```ruby
39
39
  graph = Graphwerk::Builders::Graph.new(
@@ -17,7 +17,7 @@ module Graphwerk
17
17
  }
18
18
 
19
19
  DEFAULT_OPTIONS = T.let({
20
- layout: Graphwerk::Layout::Fdp,
20
+ layout: Graphwerk::Layout::Dot,
21
21
  application: {
22
22
  style: 'filled',
23
23
  fillcolor: '#333333',
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Graphwerk
5
+ # https://graphviz.org/documentation/#layout-manual-pages
5
6
  class Layout < T::Enum
6
7
  enums do
7
8
  Dot = new
@@ -11,21 +11,14 @@ module Graphwerk
11
11
  @package = package
12
12
  end
13
13
 
14
- WITHOUT_ROOT_FOLDER = T.let(
15
- ->(package_name) { package_name.split('/', 2).last },
16
- T.proc.params(package_name: String).returns(String)
17
- )
18
-
19
14
  sig { returns(String) }
20
15
  def name
21
- return WITHOUT_ROOT_FOLDER.call(@package.name) unless root?
22
-
23
- Constants::ROOT_PACKAGE_NAME
16
+ package_name.node_name
24
17
  end
25
18
 
26
19
  sig { returns(T::Array[String]) }
27
20
  def dependencies
28
- @package.dependencies.map { |dependency| WITHOUT_ROOT_FOLDER.call(dependency) }
21
+ @package.dependencies.map { |dependency| Name.new(dependency).node_name }
29
22
  end
30
23
 
31
24
  ROOT_COLOR = 'black'
@@ -33,24 +26,54 @@ module Graphwerk
33
26
 
34
27
  sig { returns(String) }
35
28
  def color
36
- return ROOT_COLOR if root?
29
+ return ROOT_COLOR if package_name.root?
37
30
 
38
31
  COMPONENT_COLOR
39
32
  end
40
33
 
41
34
  private
42
35
 
43
- ROOT_PACKAGE = '.'
36
+ sig { returns(Name) }
37
+ def package_name
38
+ @package_name = T.let(@package_name, T.nilable(Name))
39
+ @package_name ||= Name.new(@package.name)
40
+ end
41
+
42
+ class Name
43
+ extend T::Sig
44
+
45
+ sig { params(package_name: String).void }
46
+ def initialize(package_name)
47
+ @package_name = package_name
48
+ end
49
+
50
+ sig { returns(String) }
51
+ def node_name
52
+ return without_root_package unless root?
53
+
54
+ Constants::ROOT_PACKAGE_NAME
55
+ end
56
+
57
+ ROOT_PACKAGE = '.'
58
+
59
+ sig { returns(T::Boolean) }
60
+ def root?
61
+ @package_name == ROOT_PACKAGE
62
+ end
63
+
64
+ private
65
+
66
+ sig { returns(String) }
67
+ def without_root_package
68
+ T.must(@package_name.split('/', 2).last)
69
+ end
44
70
 
45
- sig { returns(T::Boolean) }
46
- def root?
47
- @package.name == ROOT_PACKAGE
71
+ private_constant :ROOT_PACKAGE
48
72
  end
49
73
 
50
- private_constant :ROOT_PACKAGE,
51
- :ROOT_COLOR,
74
+ private_constant :ROOT_COLOR,
52
75
  :COMPONENT_COLOR,
53
- :WITHOUT_ROOT_FOLDER
76
+ :Name
54
77
  end
55
78
  end
56
79
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Graphwerk
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Giles
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport