snapbot 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/Steepfile +1 -1
- data/lib/snapbot/diagram/renderer.rb +7 -7
- data/lib/snapbot/diagram.rb +10 -6
- data/lib/snapbot/version.rb +1 -1
- data/sig/lib/snapbot/diagram/renderer.rbs +4 -3
- data/sig/lib/snapbot/diagram.rbs +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd8932c76924b2ce01335b13174915694258dcd419d5c7da3fe5daa45a7e66c7
|
4
|
+
data.tar.gz: 9aa4282ef7e47c1789b742f28a977c8ea387d526ed0a8b4d524b6e205120d4f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c3e26e2eedb55db8876619da0c63fb79754b8c584d3ed1cf6599fbc37d8f8174af90f706bf6c5ee34e88e60a4482ab57b438613c04e426992a0f8ab80b13499
|
7
|
+
data.tar.gz: 3153f489921edecb2ca66bb7781911d0ff13e3ce563749773e649cb5a8c1c6229cc67f89cfbdcb96e17e9270cfcdc65ea2a4af7aa10e2cec8f29f6977e397357
|
data/README.md
CHANGED
@@ -20,13 +20,19 @@ Install this first, then add the gem to your project's `:test` group in the gemf
|
|
20
20
|
end
|
21
21
|
```
|
22
22
|
|
23
|
-
|
23
|
+
`include Snapbot::Diagram` in your tests.
|
24
24
|
|
25
|
+
For RSpec, you may prefer to put something like
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
RSpec.config do |config|
|
29
|
+
config.include Snapbot::Diagram, type: :feature
|
30
|
+
end
|
25
31
|
```
|
26
|
-
include Snapbot::Diagram
|
27
|
-
```
|
28
32
|
|
29
|
-
|
33
|
+
in your `spec/rails_helper` to have it mixed in automatically (to features, in this case).
|
34
|
+
|
35
|
+
## Usage example
|
30
36
|
|
31
37
|
```
|
32
38
|
blog = Blog.create(title: 'My blog')
|
data/Steepfile
CHANGED
@@ -26,7 +26,7 @@ target :lib do
|
|
26
26
|
# lib/snapbot/diagram/renderer.rb:21:58: [error] The method cannot be called with a block
|
27
27
|
# │ Diagnostic ID: Ruby::UnexpectedBlockGiven
|
28
28
|
# │
|
29
|
-
# └ IO.popen("dot -Tsvg -o #{
|
29
|
+
# └ IO.popen("dot -Tsvg -o #{DEFAULT_OUTPUT_FILENAME}", "w+") do |pipe|
|
30
30
|
# ~~~~~~~~~
|
31
31
|
#
|
32
32
|
# This disables that ^^ but probably a bit too much. Can we restrict to renderer.rb?
|
@@ -7,23 +7,23 @@ module Snapbot
|
|
7
7
|
# Render some DOT via Graphviz dot command line
|
8
8
|
class Renderer
|
9
9
|
INSTALL_GRAPHVIZ_URL = "https://graphviz.org/download/#executable-packages"
|
10
|
-
|
10
|
+
DEFAULT_OUTPUT_FILENAME = "tmp/models.svg"
|
11
11
|
|
12
12
|
def initialize(dot)
|
13
13
|
@dot = dot
|
14
14
|
end
|
15
15
|
|
16
|
-
def save
|
16
|
+
def save(path = DEFAULT_OUTPUT_FILENAME)
|
17
17
|
ensure_graphviz
|
18
|
-
FileUtils.rm(
|
19
|
-
FileUtils.mkdir_p(File.dirname(
|
18
|
+
FileUtils.rm(path, force: true)
|
19
|
+
FileUtils.mkdir_p(File.dirname(path))
|
20
20
|
|
21
|
-
IO.popen("dot -Tsvg -o #{
|
21
|
+
IO.popen("dot -Tsvg -o #{path}", "w") do |pipe|
|
22
22
|
pipe.puts(@dot)
|
23
23
|
end
|
24
24
|
|
25
|
-
warn "Written to #{
|
26
|
-
|
25
|
+
warn "Written to #{path}"
|
26
|
+
path
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
data/lib/snapbot/diagram.rb
CHANGED
@@ -7,17 +7,21 @@ module Snapbot
|
|
7
7
|
# Print the small constellation of objects in your integration test and how they relate.
|
8
8
|
# Requires Graphviz. Optimised for Mac. YMMV.
|
9
9
|
module Diagram
|
10
|
-
def save_and_open_diagram(**args)
|
11
|
-
|
12
|
-
dot = DotGenerator.new(**args).dot
|
13
|
-
filename = Renderer.new(dot).save
|
10
|
+
def save_and_open_diagram(path = Renderer::DEFAULT_OUTPUT_FILENAME, **args)
|
11
|
+
filename = save_diagram(path, **args)
|
14
12
|
|
15
13
|
unless launchy_present?
|
16
|
-
warn "Cannot open diagram – install `launchy`.
|
14
|
+
warn "Cannot open diagram – install `launchy`."
|
17
15
|
return
|
18
16
|
end
|
19
17
|
|
20
|
-
Launchy.open(
|
18
|
+
Launchy.open(filename)
|
19
|
+
end
|
20
|
+
|
21
|
+
def save_diagram(path = Renderer::DEFAULT_OUTPUT_FILENAME, **args)
|
22
|
+
args.reverse_merge!(rspec: !!defined?(RSpec))
|
23
|
+
dot = DotGenerator.new(**args).dot
|
24
|
+
Renderer.new(dot).save(path)
|
21
25
|
end
|
22
26
|
|
23
27
|
def launchy_present?
|
data/lib/snapbot/version.rb
CHANGED
@@ -2,18 +2,19 @@ module Snapbot
|
|
2
2
|
module Diagram
|
3
3
|
# Render some DOT via Graphviz dot command line
|
4
4
|
class Renderer
|
5
|
-
INSTALL_GRAPHVIZ_URL:
|
6
|
-
|
5
|
+
INSTALL_GRAPHVIZ_URL: String
|
6
|
+
DEFAULT_OUTPUT_FILENAME: String
|
7
7
|
|
8
8
|
@dot: String
|
9
9
|
|
10
10
|
def initialize: (String dot) -> void
|
11
|
-
def save: () -> String
|
11
|
+
def save: (?String path) -> String
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def graphviz_executable: () -> ::String
|
16
16
|
def ensure_graphviz: () -> void
|
17
|
+
def launchy_present?: () -> bool
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/sig/lib/snapbot/diagram.rbs
CHANGED
@@ -2,7 +2,8 @@ module Snapbot
|
|
2
2
|
# Print the small constellation of objects in your integration test and how they relate.
|
3
3
|
# Requires Graphviz. Optimised for Mac. YMMV.
|
4
4
|
module Diagram
|
5
|
-
def
|
5
|
+
def save_diagram: (?String path, **untyped args) -> (nil | untyped)
|
6
|
+
def save_and_open_diagram: (?String path, **untyped args) -> (nil | untyped)
|
6
7
|
|
7
8
|
def open_command: () -> untyped
|
8
9
|
end
|