snapbot 0.1.0 → 0.1.3
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/dot_generator.rb +1 -1
- data/lib/snapbot/diagram/renderer.rb +45 -0
- data/lib/snapbot/diagram.rb +18 -1
- data/lib/snapbot/reflector.rb +4 -2
- 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: bb58059025b35d29e5d762be3719f21461f225a2950c51efe54161009b1412ca
|
4
|
+
data.tar.gz: a08b6fe2a72289b2946ac7461920863a7226a9d24b12a24d3b23dbe1f2ca00dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31970a0125ab31512d051b4a8dac26e324fa556dd6ccfdffa1a83dc8bc9b6a962f5423150bcc634c45420cc59e12258b3d034b1210765b7c63cbba033b8a3277
|
7
|
+
data.tar.gz: 530cebe2837a43ea3a9bddcdb63ed3bdda8666d3a2dd05cb79926e3d6f9c5b3c41da750e8d5dfc6c67fa3784c4f1c672b4620c0e2d135a1825bf87b1182b76fa
|
data/.rubocop.yml
CHANGED
@@ -40,7 +40,7 @@ module Snapbot
|
|
40
40
|
def collect_lets(example)
|
41
41
|
@lets_by_value = RSpec::Lets.new(example).collect.each_with_object({}) do |sym, lets_by_value|
|
42
42
|
value = example.send(sym) unless @ignore_lets.include?(sym)
|
43
|
-
lets_by_value[value] = sym if value.is_a?(
|
43
|
+
lets_by_value[value] = sym if value.is_a?(reflector.base_activerecord_class)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -0,0 +1,45 @@
|
|
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
|
+
FileUtils.mkdir_p(File.dirname(OUTPUT_FILENAME))
|
20
|
+
|
21
|
+
IO.popen("dot -Tsvg -o #{OUTPUT_FILENAME}", "w") do |pipe|
|
22
|
+
pipe.puts(@dot)
|
23
|
+
end
|
24
|
+
|
25
|
+
warn "Written to #{OUTPUT_FILENAME}"
|
26
|
+
OUTPUT_FILENAME
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def graphviz_executable
|
32
|
+
`which dot`
|
33
|
+
end
|
34
|
+
|
35
|
+
def ensure_graphviz
|
36
|
+
return unless graphviz_executable.empty?
|
37
|
+
|
38
|
+
warn <<~GRAPHVIZ
|
39
|
+
The graphviz executable `dot` was not found.
|
40
|
+
Install from #{INSTALL_GRAPHVIZ_URL}
|
41
|
+
GRAPHVIZ
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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/reflector.rb
CHANGED
@@ -5,12 +5,14 @@ require "active_record"
|
|
5
5
|
module Snapbot
|
6
6
|
# Reflect models and instances in a way that's useful for generating a diagram
|
7
7
|
class Reflector
|
8
|
-
|
8
|
+
def base_activerecord_class
|
9
|
+
defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base
|
10
|
+
end
|
9
11
|
|
10
12
|
def models(only_with_records: true)
|
11
13
|
@models ||= begin
|
12
14
|
Rails.application.eager_load! if defined?(Rails)
|
13
|
-
|
15
|
+
base_activerecord_class.descendants.reject do |c|
|
14
16
|
c.to_s == "Schema" || (only_with_records && c.count.zero?)
|
15
17
|
end
|
16
18
|
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.3
|
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
|