snapbot 0.1.0 → 0.1.1

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: 9ff9b478fc49144d2edf97c515e52f946b3f73a0d939e0de6d9789e6ab207a1b
4
- data.tar.gz: 3d10ece40e5e1e2dfc67f8552746f6c2f326b54d0977a2a39764f1ba008a9a97
3
+ metadata.gz: aa9a6b0cbc5334ac7078254f385f9c859c0ea22d7ca4821741bade0b4c32cca6
4
+ data.tar.gz: 8e69a33b99977466a92b9772abaa2e2d889a0d7ff200ed81c5effb01581eb014
5
5
  SHA512:
6
- metadata.gz: dff17039b7af000c3d9a6fb17ba2fc21af8da0a0ab3a72a9b2af098f8b0e06b7c5b3a3230b547d78886f5e9bd320c9c30f2095fdb9e55ee5c892488be5c04e6b
7
- data.tar.gz: 578806b5e7c84b72691ebad4069ac39a51c0fcd04b79b62282fbb57fbf096dc88e29e8c23d801e1ed230a8925dc4b004d1c80b80520d7eb3ece9caf612e208e3
6
+ metadata.gz: 1de519ae9f8e26a44d081682b83ca89d101daf00f5665c7d04a4ed1bb7c8ee701a72b476b45d9d5760ff2621e498d8bbe0ddfb3bde386fc4f188a16cee3c82db
7
+ data.tar.gz: 6f549408fbffc23fc5f96f620dc0be49df614b84ce0e5c913fb375422bcec052f36e065a63080f03be3a2992c7f7a519873ab0efcb31bd9610e5b2f2bdf2340e
data/.rubocop.yml CHANGED
@@ -7,6 +7,10 @@ Metrics/BlockLength:
7
7
  - spec/**/*_spec.rb
8
8
  - snapbot.gemspec
9
9
 
10
+ Style/StderrPuts:
11
+ Exclude:
12
+ - lib/snapbot/diagram/renderer.rb
13
+
10
14
  Style/StringLiterals:
11
15
  Enabled: true
12
16
  EnforcedStyle: double_quotes
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ module Snapbot
6
+ module Diagram
7
+ # Render some DOT via Graphviz dot command line
8
+ class Renderer
9
+ INSTALL_GRAPHVIZ_URL = "https://graphviz.org/download/#executable-packages"
10
+ OUTPUT_FILENAME = "tmp/models.svg"
11
+
12
+ def initialize(dot)
13
+ @dot = dot
14
+ end
15
+
16
+ def save
17
+ ensure_graphviz
18
+ FileUtils.rm(OUTPUT_FILENAME, force: true)
19
+ IO.popen("dot -Tsvg -o #{OUTPUT_FILENAME}", "w") do |pipe|
20
+ pipe.puts(@dot)
21
+ end
22
+
23
+ warn "Written to #{OUTPUT_FILENAME}"
24
+ OUTPUT_FILENAME
25
+ end
26
+
27
+ private
28
+
29
+ def graphviz_executable
30
+ `which dot`
31
+ end
32
+
33
+ def ensure_graphviz
34
+ return unless graphviz_executable.empty?
35
+
36
+ warn <<~GRAPHVIZ
37
+ The graphviz executable `dot` was not found.
38
+ Install from #{INSTALL_GRAPHVIZ_URL}
39
+ GRAPHVIZ
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,11 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "snapbot/diagram/dot_generator"
4
+ require "snapbot/diagram/renderer"
5
+ require "open3"
6
+
3
7
  module Snapbot
4
8
  # Print the small constellation of objects in your integration test and how they relate.
5
9
  # Requires Graphviz. Optimised for Mac. YMMV.
6
10
  module Diagram
7
11
  def save_and_open_diagram(**args)
8
- DotGenerator.new(**args).open
12
+ dot = DotGenerator.new(**args).dot
13
+ filename = Renderer.new(dot).save
14
+
15
+ unless open_command.present?
16
+ warn "No `open` command available. File saved to #{filename}"
17
+ return
18
+ end
19
+
20
+ _stdout, stderr, status = Open3.capture3("#{open_command} #{filename}")
21
+ raise stderr unless status.exitstatus.zero?
22
+ end
23
+
24
+ def open_command
25
+ `which open`.chomp
9
26
  end
10
27
  end
11
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snapbot
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Garner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-05 00:00:00.000000000 Z
11
+ date: 2022-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -99,6 +99,7 @@ files:
99
99
  - lib/snapbot/diagram.rb
100
100
  - lib/snapbot/diagram/dot_generator.rb
101
101
  - lib/snapbot/diagram/dot_generator/relationship.rb
102
+ - lib/snapbot/diagram/renderer.rb
102
103
  - lib/snapbot/reflector.rb
103
104
  - lib/snapbot/rspec/lets.rb
104
105
  - lib/snapbot/version.rb