derketo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +3 -0
- data/.gitignore +6 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +4 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +41 -0
- data/Rakefile +25 -0
- data/derketo.gemspec +37 -0
- data/lib/derketo.rb +4 -0
- data/lib/derketo/event_trace.rb +35 -0
- data/lib/derketo/events/call.rb +14 -0
- data/lib/derketo/events/event.rb +47 -0
- data/lib/derketo/events/return.rb +14 -0
- data/lib/derketo/helpers.rb +13 -0
- data/lib/derketo/middleware.rb +18 -0
- data/lib/derketo/railtie.rb +10 -0
- data/lib/derketo/serializers/mermaid.rb +26 -0
- data/lib/derketo/tracer.rb +27 -0
- data/lib/derketo/version.rb +4 -0
- data/spec/derketo/event_trace_spec.rb +60 -0
- data/spec/derketo/events/call_spec.rb +21 -0
- data/spec/derketo/events/event_spec.rb +34 -0
- data/spec/derketo/events/return_spec.rb +21 -0
- data/spec/derketo/helpers_spec.rb +53 -0
- data/spec/derketo/serializers/mermaid_spec.rb +30 -0
- data/spec/derketo/tracer_spec.rb +28 -0
- data/spec/derketo_spec.rb +8 -0
- data/spec/fixtures/mermaid.mmd +4 -0
- data/spec/spec_helper.rb +22 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1cd0765e76ebfc085bc1c188129bf8325426f948
|
4
|
+
data.tar.gz: bc980fd96d38642276207304b8e49e81fe2096e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a20c173ea69b8aad777094c0e2043257883ea89f8a4f3596f7ec88cef8307474843ddd6f1a178551ba5090b31c5cfdb48524d98a94e2cf32425b0dff90c79d1d
|
7
|
+
data.tar.gz: d74f290acc033f60896f85c70296cc5ff10aa2daf725709563ce3234421107ed5c957f2f080c91afb541cd14ae6cd560822211c12fb64cf16713c034536f5815
|
data/.document
ADDED
data/.gitignore
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title "derketo Documentation" --protected
|
data/ChangeLog.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2018 Arcadia Power
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Derketo - Generate Sequence Diagrams with Ruby Tracepoint & Mermaid.js
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/arcadiapower/derketo.svg?branch=master)](https://travis-ci.org/arcadiapower/derketo) [![Code Climate](https://codeclimate.com/github/arcadiapower/derketo/badges/gpa.svg)](https://codeclimate.com/github/arcadiapower/derketo)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Derketo is a gem that allows you to easily generate seqeuence diagrams of your code paths by serializing a [Tracepoint](https://ruby-doc.org/core-2.5.0/TracePoint.html) object into [mermaid.js](https://mermaidjs.github.io/).
|
8
|
+
|
9
|
+
Sequence diagrams:
|
10
|
+
1. Help you discover architectural, interface and logic problems early.
|
11
|
+
2. Become valuable collaboration tools during design meetings because they allow you to discuss the design in concrete terms.
|
12
|
+
3. Abstract much of the implementation detail and provide a high level view of system behavior, thus helping you with documentation.
|
13
|
+
|
14
|
+
## Preview
|
15
|
+
Here's an example sequence diagram that was generated by Derketo:
|
16
|
+
|
17
|
+
![Sequence Diagram]()
|
18
|
+
**TODO**: Add PNG of MMD output.
|
19
|
+
|
20
|
+
## Requirements
|
21
|
+
|
22
|
+
## Getting Started
|
23
|
+
require 'derketo'
|
24
|
+
|
25
|
+
tracer = Derketo::Tracer.new()
|
26
|
+
tracer.trace { Mermaid.new.sing }
|
27
|
+
serializaton = Derketo::Serializers::Mermaid.new(tracer).serialize
|
28
|
+
Derketo::Helpers.write('./tmp/test.mmd', serialization)
|
29
|
+
|
30
|
+
## Integrate with a Rack Application
|
31
|
+
|
32
|
+
All you should have to do is define the root of your project in an ENV called `DERKETO_ROOT` and `require 'derketo/middleware'`.
|
33
|
+
## Install
|
34
|
+
|
35
|
+
$ gem install derketo
|
36
|
+
|
37
|
+
## Copyright
|
38
|
+
|
39
|
+
Copyright (c) 2018 Arcadia Power
|
40
|
+
|
41
|
+
See {file:LICENSE.txt} for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler/setup'
|
7
|
+
rescue LoadError => e
|
8
|
+
abort e.message
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
|
14
|
+
require 'rubygems/tasks'
|
15
|
+
Gem::Tasks.new
|
16
|
+
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
RSpec::Core::RakeTask.new
|
19
|
+
|
20
|
+
task :test => :spec
|
21
|
+
task :default => :spec
|
22
|
+
|
23
|
+
require 'yard'
|
24
|
+
YARD::Rake::YardocTask.new
|
25
|
+
task :doc => :yard
|
data/derketo.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'derketo/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "derketo"
|
9
|
+
gem.version = Derketo::VERSION
|
10
|
+
gem.summary = 'Turn your code into a mermaid.'
|
11
|
+
gem.description = 'An easy way to trace your code and visualize it as a sequence diagram.'
|
12
|
+
gem.license = "MIT"
|
13
|
+
gem.authors = ["Justin Searles"]
|
14
|
+
gem.email = "justin.searles@arcadiapower.com"
|
15
|
+
gem.homepage = "https://rubygems.org/gems/derketo"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
|
19
|
+
`git submodule --quiet foreach --recursive pwd`.split($/).each do |submodule|
|
20
|
+
submodule.sub!("#{Dir.pwd}/",'')
|
21
|
+
|
22
|
+
Dir.chdir(submodule) do
|
23
|
+
`git ls-files`.split($/).map do |subpath|
|
24
|
+
gem.files << File.join(submodule,subpath)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
29
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
30
|
+
gem.require_paths = ['lib']
|
31
|
+
|
32
|
+
gem.add_development_dependency 'bundler', '~> 1.10'
|
33
|
+
gem.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
36
|
+
gem.add_development_dependency 'yard', '~> 0.8'
|
37
|
+
end
|
data/lib/derketo.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Derketo
|
2
|
+
class EventTrace
|
3
|
+
attr_accessor :first, :last, :length
|
4
|
+
def initialize
|
5
|
+
@first = nil
|
6
|
+
@last = nil
|
7
|
+
@length = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def push(event)
|
11
|
+
if @first.nil?
|
12
|
+
@first = event
|
13
|
+
else
|
14
|
+
event.previous = @last
|
15
|
+
@last.next = event
|
16
|
+
end
|
17
|
+
@last = event
|
18
|
+
@length += 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def all
|
22
|
+
@_events = []
|
23
|
+
event = @first
|
24
|
+
while event.nil? == false
|
25
|
+
@_events << event
|
26
|
+
event = event.next
|
27
|
+
end
|
28
|
+
@_events
|
29
|
+
end
|
30
|
+
|
31
|
+
def empty?
|
32
|
+
@length == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'derketo/events/event'
|
2
|
+
module Derketo
|
3
|
+
module Events
|
4
|
+
class Call < Event
|
5
|
+
def to_mermaid
|
6
|
+
if parameters.empty?
|
7
|
+
"\t#{previous.class_name}->>#{class_name}: #{method_id}\n"
|
8
|
+
else
|
9
|
+
"\t#{previous.class_name}->>#{class_name}: #{method_id}(#{parameters})\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'json'
|
2
|
+
module Derketo
|
3
|
+
class Event
|
4
|
+
attr_accessor :class_name, :return_value, :type, :method_id, :parameters, :previous, :next
|
5
|
+
|
6
|
+
def initialize(tracepoint)
|
7
|
+
@class_name = tracepoint.defined_class.to_s
|
8
|
+
@return_value = tracepoint.event == :return ? tracepoint.return_value : nil
|
9
|
+
@type = tracepoint.event
|
10
|
+
@method_id = tracepoint.method_id
|
11
|
+
@parameters = tracepoint.self.method(tracepoint.method_id).parameters
|
12
|
+
@previous = self
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
{
|
17
|
+
class: @class_name,
|
18
|
+
type: @type,
|
19
|
+
method: @method_id,
|
20
|
+
parameters: @parameters,
|
21
|
+
return_value: @return_value
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# {
|
26
|
+
# "class": "Mermaid",
|
27
|
+
# "type": "call",
|
28
|
+
# "method": "initialize",
|
29
|
+
# "parameters": [],
|
30
|
+
# "return_value": null
|
31
|
+
# }
|
32
|
+
def to_json
|
33
|
+
JSON.generate(to_h)
|
34
|
+
end
|
35
|
+
|
36
|
+
# {
|
37
|
+
# :class=>"Mermaid",
|
38
|
+
# :type=>:call,
|
39
|
+
# :method=>:initialize,
|
40
|
+
# :parameters=>[],
|
41
|
+
# :return_value=>nil
|
42
|
+
# }
|
43
|
+
def to_s
|
44
|
+
to_h.to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'derketo/events/event'
|
2
|
+
module Derketo
|
3
|
+
module Events
|
4
|
+
class Return < Event
|
5
|
+
def to_mermaid
|
6
|
+
if return_value.nil?
|
7
|
+
"\t#{previous.class_name}-->>#{class_name}: return\n"
|
8
|
+
else
|
9
|
+
"\t#{previous.class_name}-->>#{class_name}: #{return_value}\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Derketo
|
2
|
+
module Helpers
|
3
|
+
def clean(string)
|
4
|
+
string.gsub('::', '/').tr(',', '|').tr(':', '=').delete('#').delete('<').delete('>')
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.write(filename, text)
|
8
|
+
File.open(filename, 'w') do |file|
|
9
|
+
file << text
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'derketo/tracer'
|
2
|
+
require 'derketo/serializers/mermaid'
|
3
|
+
|
4
|
+
module Derketo
|
5
|
+
class Middleware
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
tracer = Derketo::Tracer.new(ENV['DERKETO_ROOT'])
|
12
|
+
response = tracer.trace(@app.call(env))
|
13
|
+
serializaton = Derketo::Serializers::Mermaid.new(tracer).serialize
|
14
|
+
Derketo::Helpers.write('./tmp/derketo.mmd', serialization)
|
15
|
+
response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'derketo/sequencer'
|
2
|
+
require 'derketo/middleware'
|
3
|
+
|
4
|
+
module Derketo
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer "derketo.configure_rails_initialization" do
|
7
|
+
Rails.application.middleware.insert_before(ActionDispatch::Static, Derketo::Middleware)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'derketo/helpers'
|
2
|
+
module Derketo
|
3
|
+
module Serializers
|
4
|
+
class Mermaid
|
5
|
+
include Derketo::Helpers
|
6
|
+
|
7
|
+
attr_accessor :text
|
8
|
+
def initialize(tracer)
|
9
|
+
events = tracer.events.all
|
10
|
+
@text = "sequenceDiagram\n"
|
11
|
+
events.map(&:class_name).uniq.map do |class_name|
|
12
|
+
@text << participant(class_name)
|
13
|
+
end
|
14
|
+
@text << events.map(&:to_mermaid).join
|
15
|
+
end
|
16
|
+
|
17
|
+
def participant(class_name)
|
18
|
+
"\tparticipant #{clean(class_name)}\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
def serialize
|
22
|
+
@text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'derketo/event_trace'
|
2
|
+
require 'derketo/events/call'
|
3
|
+
require 'derketo/events/return'
|
4
|
+
module Derketo
|
5
|
+
class Tracer
|
6
|
+
attr_accessor :events
|
7
|
+
def initialize(scope: nil)
|
8
|
+
@events = Derketo::EventTrace.new
|
9
|
+
@tracepoint = TracePoint.new(:call, :return) do |tp|
|
10
|
+
if scope.nil? || tp.path.include?(scope)
|
11
|
+
if tp.event == :call
|
12
|
+
@events.push(Derketo::Events::Call.new(tp))
|
13
|
+
elsif tp.event == :return
|
14
|
+
@events.push(Derketo::Events::Return.new(tp))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def trace
|
21
|
+
@tracepoint.enable
|
22
|
+
response = yield
|
23
|
+
@tracepoint.disable
|
24
|
+
response
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'derketo/event_trace'
|
3
|
+
|
4
|
+
describe Derketo::EventTrace do
|
5
|
+
let(:trace) { Derketo::EventTrace.new }
|
6
|
+
let(:node) { Node.new }
|
7
|
+
|
8
|
+
describe '#push' do
|
9
|
+
it 'adds the first event to the trace' do
|
10
|
+
trace.push(node)
|
11
|
+
expect(trace.first).to eq(node)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'adds two events to the trace' do
|
15
|
+
trace.push(node)
|
16
|
+
new_node = Node.new
|
17
|
+
trace.push(new_node)
|
18
|
+
expect(trace.first).to_not eq(new_node)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the event\'s previous link' do
|
22
|
+
trace.push(node)
|
23
|
+
new_node = Node.new
|
24
|
+
trace.push(new_node)
|
25
|
+
expect(new_node.previous).to eq(node)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#last' do
|
30
|
+
it 'returns the first event if there is only one' do
|
31
|
+
trace.push(node)
|
32
|
+
expect(trace.last).to eq(node)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns the last event if there is more than one' do
|
36
|
+
trace.push(node)
|
37
|
+
new_node = Node.new
|
38
|
+
trace.push(new_node)
|
39
|
+
expect(trace.last).to eq(new_node)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#all' do
|
44
|
+
it 'returns an empty array if there are no events' do
|
45
|
+
expect(trace.all).to eq([])
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns an array with one element if there is one event' do
|
49
|
+
trace.push(node)
|
50
|
+
expect(trace.all).to eq([node])
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns an array with multiple elements when there are multiple events' do
|
54
|
+
trace.push(node)
|
55
|
+
new_node = Node.new
|
56
|
+
trace.push(new_node)
|
57
|
+
expect(trace.all.count).to eq(2)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'derketo/tracer'
|
3
|
+
|
4
|
+
describe Derketo::Events::Call do
|
5
|
+
let(:tracer) { Derketo::Tracer.new }
|
6
|
+
let(:example) {
|
7
|
+
m = Mermaid.new
|
8
|
+
tracer.trace {
|
9
|
+
m.sing
|
10
|
+
}
|
11
|
+
}
|
12
|
+
let(:event) { tracer.events.first }
|
13
|
+
|
14
|
+
before(:each) { example }
|
15
|
+
|
16
|
+
describe '#to_mermaid' do
|
17
|
+
it 'returns a mmd formatted string' do
|
18
|
+
expect(event.to_mermaid).to eq(" Mermaid->>Mermaid: sing\n")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'derketo/tracer'
|
3
|
+
|
4
|
+
describe Derketo::Event do
|
5
|
+
|
6
|
+
let(:tracer) { Derketo::Tracer.new }
|
7
|
+
let(:example) {
|
8
|
+
m = Mermaid.new
|
9
|
+
tracer.trace {
|
10
|
+
m.sing
|
11
|
+
}
|
12
|
+
}
|
13
|
+
let(:event) { tracer.events.first }
|
14
|
+
|
15
|
+
before(:each) { example }
|
16
|
+
|
17
|
+
describe '#to_h' do
|
18
|
+
it 'returns a Hash' do
|
19
|
+
expect(event.to_h.class).to eq(Hash)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#to_json' do
|
24
|
+
it 'returns a JSON formatted String' do
|
25
|
+
expect(event.to_json.class).to eq(String)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#to_s' do
|
30
|
+
it 'returns a String' do
|
31
|
+
expect(event.to_s.class).to eq(String)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'derketo/tracer'
|
3
|
+
|
4
|
+
describe Derketo::Events::Return do
|
5
|
+
let(:tracer) { Derketo::Tracer.new }
|
6
|
+
let(:example) {
|
7
|
+
m = Mermaid.new
|
8
|
+
tracer.trace {
|
9
|
+
m.sing
|
10
|
+
}
|
11
|
+
}
|
12
|
+
let(:event) { tracer.events.last }
|
13
|
+
|
14
|
+
before(:each) { example }
|
15
|
+
|
16
|
+
describe '#to_mermaid' do
|
17
|
+
it 'returns a mmd formatted string' do
|
18
|
+
expect(event.to_mermaid).to eq(" Mermaid-->>Mermaid: a song\n")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'derketo/helpers'
|
2
|
+
|
3
|
+
describe Derketo::Helpers do
|
4
|
+
class DummyClass
|
5
|
+
end
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@dummy_class = DummyClass.new
|
9
|
+
@dummy_class.extend(Derketo::Helpers)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.clean' do
|
13
|
+
it 'replaces "::" with "/"' do
|
14
|
+
expect(@dummy_class.clean('::')).to eq('/')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'removes "#"' do
|
18
|
+
expect(@dummy_class.clean('#')).to eq('')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'replaces ":" with "="' do
|
22
|
+
expect(@dummy_class.clean(':')).to eq('=')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'removes "<"' do
|
26
|
+
expect(@dummy_class.clean('<')).to eq('')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'removes ">"' do
|
30
|
+
expect(@dummy_class.clean('>')).to eq('')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'replaces "," with "|"' do
|
34
|
+
expect(@dummy_class.clean(',')).to eq('|')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.write' do
|
39
|
+
before(:all) do
|
40
|
+
Dir.mkdir(File.expand_path(File.dirname(__FILE__) + '../../tmp/'))
|
41
|
+
end
|
42
|
+
|
43
|
+
after(:all) do
|
44
|
+
system("rm -r #{File.expand_path(File.dirname(__FILE__) + '../../tmp/')}")
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'writes to a file' do
|
48
|
+
filename = File.expand_path(File.dirname(__FILE__) + '../../tmp/test.txt')
|
49
|
+
@dummy_class.write(filename, 'test')
|
50
|
+
expect(File.file?(filename)).to eq(true)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'derketo/serializers/mermaid'
|
3
|
+
|
4
|
+
describe Derketo::Serializers::Mermaid do
|
5
|
+
let(:tracer) { Derketo::Tracer.new }
|
6
|
+
let(:example) {
|
7
|
+
m = Mermaid.new
|
8
|
+
tracer.trace {
|
9
|
+
m.sing
|
10
|
+
}
|
11
|
+
}
|
12
|
+
let(:serializer) { example; described_class.new(tracer) }
|
13
|
+
|
14
|
+
describe '.initialize' do
|
15
|
+
it 'first line is sequenceDiagram' do
|
16
|
+
expect(serializer.text.slice(0..15)).to eq("sequenceDiagram\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sequences mermaid strings' do
|
20
|
+
fixture = File.read(File.expand_path(File.dirname(__FILE__) + '../../../fixtures/mermaid.mmd'))
|
21
|
+
expect(serializer.text).to eq(fixture)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#particpant' do
|
26
|
+
it 'formats correctly' do
|
27
|
+
expect(serializer.participant('Test')).to eq("\tparticipant Test\n")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'derketo/tracer'
|
3
|
+
|
4
|
+
describe Derketo::Tracer do
|
5
|
+
|
6
|
+
describe '#trace' do
|
7
|
+
let(:tracer) { Derketo::Tracer.new }
|
8
|
+
let(:example) {
|
9
|
+
m = Mermaid.new
|
10
|
+
tracer.trace {
|
11
|
+
m.sing
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
it 'returns the original response' do
|
16
|
+
expect(example).to eq('a song')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'captures the trace' do
|
20
|
+
example
|
21
|
+
expect(tracer.events.empty?).to eq(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'only captures the specified trace when given a root' do
|
25
|
+
skip 'need to put the Mermaid class into a spec dummy directory'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'derketo/version'
|
3
|
+
|
4
|
+
include Derketo
|
5
|
+
|
6
|
+
class Mermaid
|
7
|
+
def initialize; end
|
8
|
+
def sing
|
9
|
+
'a song'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Node
|
14
|
+
attr_accessor :previous, :next
|
15
|
+
def initialize
|
16
|
+
@previous = nil
|
17
|
+
@next = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
SPEC_ROOT = File.dirname(__FILE__)
|
22
|
+
puts SPEC_ROOT
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: derketo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Searles
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubygems-tasks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
description: An easy way to trace your code and visualize it as a sequence diagram.
|
84
|
+
email: justin.searles@arcadiapower.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".document"
|
90
|
+
- ".gitignore"
|
91
|
+
- ".yardopts"
|
92
|
+
- ChangeLog.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- derketo.gemspec
|
98
|
+
- lib/derketo.rb
|
99
|
+
- lib/derketo/event_trace.rb
|
100
|
+
- lib/derketo/events/call.rb
|
101
|
+
- lib/derketo/events/event.rb
|
102
|
+
- lib/derketo/events/return.rb
|
103
|
+
- lib/derketo/helpers.rb
|
104
|
+
- lib/derketo/middleware.rb
|
105
|
+
- lib/derketo/railtie.rb
|
106
|
+
- lib/derketo/serializers/mermaid.rb
|
107
|
+
- lib/derketo/tracer.rb
|
108
|
+
- lib/derketo/version.rb
|
109
|
+
- spec/derketo/event_trace_spec.rb
|
110
|
+
- spec/derketo/events/call_spec.rb
|
111
|
+
- spec/derketo/events/event_spec.rb
|
112
|
+
- spec/derketo/events/return_spec.rb
|
113
|
+
- spec/derketo/helpers_spec.rb
|
114
|
+
- spec/derketo/serializers/mermaid_spec.rb
|
115
|
+
- spec/derketo/tracer_spec.rb
|
116
|
+
- spec/derketo_spec.rb
|
117
|
+
- spec/fixtures/mermaid.mmd
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: https://rubygems.org/gems/derketo
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.6.13
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Turn your code into a mermaid.
|
143
|
+
test_files:
|
144
|
+
- spec/derketo/event_trace_spec.rb
|
145
|
+
- spec/derketo/events/call_spec.rb
|
146
|
+
- spec/derketo/events/event_spec.rb
|
147
|
+
- spec/derketo/events/return_spec.rb
|
148
|
+
- spec/derketo/helpers_spec.rb
|
149
|
+
- spec/derketo/serializers/mermaid_spec.rb
|
150
|
+
- spec/derketo/tracer_spec.rb
|
151
|
+
- spec/derketo_spec.rb
|
152
|
+
- spec/fixtures/mermaid.mmd
|
153
|
+
- spec/spec_helper.rb
|