snapbot 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b343dc1ae312d937e8999b491789a0335d79577e3a8d2ebcce764c42a4871a87
4
- data.tar.gz: 89b3faeec45989c19e9a8f3497320ddac2a7728ee91d5c784557a1235bb58ea4
3
+ metadata.gz: fd8932c76924b2ce01335b13174915694258dcd419d5c7da3fe5daa45a7e66c7
4
+ data.tar.gz: 9aa4282ef7e47c1789b742f28a977c8ea387d526ed0a8b4d524b6e205120d4f1
5
5
  SHA512:
6
- metadata.gz: a66b1ddbad1589af9bbd087ceb201d50342fe8e252e6fa1b2107878fe2e1d2a9bc306ef72c6a15b720735e0eda76324148f2317808c7aeb44fc31300350e99d1
7
- data.tar.gz: 18070e47081d20037e437a8d4c50eb50393edf23990d2102685792b51a43fde62eed90a9539cd37993d8941d080a5f44474d8e6223d500f4480109c973e81e1b
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
- Add to your tests:
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
- Use:
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 #{OUTPUT_FILENAME}", "w+") do |pipe|
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
- OUTPUT_FILENAME = "tmp/models.svg"
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(OUTPUT_FILENAME, force: true)
19
- FileUtils.mkdir_p(File.dirname(OUTPUT_FILENAME))
18
+ FileUtils.rm(path, force: true)
19
+ FileUtils.mkdir_p(File.dirname(path))
20
20
 
21
- IO.popen("dot -Tsvg -o #{OUTPUT_FILENAME}", "w") do |pipe|
21
+ IO.popen("dot -Tsvg -o #{path}", "w") do |pipe|
22
22
  pipe.puts(@dot)
23
23
  end
24
24
 
25
- warn "Written to #{OUTPUT_FILENAME}"
26
- OUTPUT_FILENAME
25
+ warn "Written to #{path}"
26
+ path
27
27
  end
28
28
 
29
29
  private
@@ -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
- args.reverse_merge!(rspec: !!defined?(RSpec))
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`. File saved to #{filename}"
14
+ warn "Cannot open diagram – install `launchy`."
17
15
  return
18
16
  end
19
17
 
20
- Launchy.open(Renderer::OUTPUT_FILENAME)
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?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snapbot
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -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: "https://graphviz.org/download/#executable-packages"
6
- OUTPUT_FILENAME: "tmp/models.svg"
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
@@ -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 save_and_open_diagram: (**untyped args) -> (nil | untyped)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Garner