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 +4 -4
- data/.rubocop.yml +4 -0
- data/lib/snapbot/diagram/renderer.rb +43 -0
- data/lib/snapbot/diagram.rb +18 -1
- data/lib/snapbot/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa9a6b0cbc5334ac7078254f385f9c859c0ea22d7ca4821741bade0b4c32cca6
|
4
|
+
data.tar.gz: 8e69a33b99977466a92b9772abaa2e2d889a0d7ff200ed81c5effb01581eb014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de519ae9f8e26a44d081682b83ca89d101daf00f5665c7d04a4ed1bb7c8ee701a72b476b45d9d5760ff2621e498d8bbe0ddfb3bde386fc4f188a16cee3c82db
|
7
|
+
data.tar.gz: 6f549408fbffc23fc5f96f620dc0be49df614b84ce0e5c913fb375422bcec052f36e065a63080f03be3a2992c7f7a519873ab0efcb31bd9610e5b2f2bdf2340e
|
data/.rubocop.yml
CHANGED
@@ -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
|
data/lib/snapbot/diagram.rb
CHANGED
@@ -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).
|
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
|
data/lib/snapbot/version.rb
CHANGED
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.
|
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-
|
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
|