graphviz_transitions 0.0.1
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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +4 -0
- data/graphviz_transitions.gemspec +25 -0
- data/lib/graphviz_transitions/railtie.rb +9 -0
- data/lib/graphviz_transitions/version.rb +3 -0
- data/lib/graphviz_transitions.rb +58 -0
- data/lib/transitions/graph.rb +16 -0
- data/spec/lib/graphviz_aasm_spec.rb +5 -0
- data/spec/spec_helper.rb +19 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 26c1aa9d0f680a3dd750b9776bb7c5a1765adcd0
|
4
|
+
data.tar.gz: 8fa7505df9933641380eeb8b611715868a02e09e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b4c908432267f598be02c9bc9ed8580e33ed5dab95bf0ec421305edb51425995f47cbb68d98f0884ed15fe9c4fd63f82ed14e70f3edea854573a6c83b2e2cc8
|
7
|
+
data.tar.gz: 7ebb86e6b8c2995f4dfbd1309bb6d99cd00d760277eb179a5ff8a0358b628e36ca0b709f21f9c07be2da5a9e644f16703bc068f41ba02d2adcc243be0d8c91ee
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Roman Trofimov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# GraphvizAasm
|
2
|
+
|
3
|
+
Adds support for generating graphs based on states, events and transitions defined for [Transitions](https://github.com/troessner/transitions) state machine using
|
4
|
+
[GraphViz](http://www.graphviz.org) and [Ruby-GraphViz](https://github.com/glejeune/Ruby-Graphviz).
|
5
|
+
It is a simplified version of the same functionality for [state_machine](https://github.com/pluginaweek/state_machine) gem.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'graphviz_transitions', group: :development
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install graphviz_transitions
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To generate a graph for a specific model:
|
24
|
+
|
25
|
+
$ rake transitions:draw CLASS=Vehicle
|
26
|
+
|
27
|
+
To save files to a specific path:
|
28
|
+
|
29
|
+
$ rake aasm:draw CLASS=Vehicle,Vehicle::Color TARGET=./tmp
|
30
|
+
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( http://github.com/itkin/graphviz_transitions/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
39
|
+
|
40
|
+
|
41
|
+
## Credit
|
42
|
+
|
43
|
+
[romatr/graphviz_aasm](https://github.com/romatr/graphviz_aasm)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'graphviz_transitions/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "graphviz_transitions"
|
7
|
+
spec.version = GraphvizTransitions::VERSION
|
8
|
+
spec.authors = ["Itkin"]
|
9
|
+
# spec.email = ["nicolas.papon@gmail.com"]
|
10
|
+
spec.summary = %q{Use Ruby-GraphViz for Transitions.}
|
11
|
+
spec.description = %q{This gem patches Transitions to be able to generate graphs using GraphViz.}
|
12
|
+
# spec.homepage = "https://github.com/romatr/graphviz_aasm"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec"
|
22
|
+
|
23
|
+
spec.add_dependency "transitions"
|
24
|
+
spec.add_dependency "ruby-graphviz"
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "transitions"
|
2
|
+
require "transitions/graph"
|
3
|
+
require "graphviz_transitions/version"
|
4
|
+
|
5
|
+
module Transitions
|
6
|
+
require "graphviz_transitions/railtie" if defined?(Rails)
|
7
|
+
|
8
|
+
Machine.class_eval do
|
9
|
+
def self.draw(class_names, options = {})
|
10
|
+
raise ArgumentError, "At least one class must be specified" unless class_names && class_names.split(',').any?
|
11
|
+
|
12
|
+
class_names.split(',').each do |class_name|
|
13
|
+
klass = class_name.constantize
|
14
|
+
|
15
|
+
graph = Transitions::Graph.new(class_name, options)
|
16
|
+
|
17
|
+
klass.get_state_machine.states.each do |state|
|
18
|
+
state.draw(graph)
|
19
|
+
end
|
20
|
+
|
21
|
+
klass.get_state_machine.events.values.each do |event|
|
22
|
+
event.draw(graph)
|
23
|
+
end
|
24
|
+
graph.output
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Transitions::State.class_eval do
|
30
|
+
|
31
|
+
def draw(graph)
|
32
|
+
node = graph.add_nodes(self.name.to_s.humanize, shape: final? ? "doublecircle" : "ellipse")
|
33
|
+
graph.add_edge(graph.add_nodes("starting_state", shape: "point"), node) if initial?
|
34
|
+
end
|
35
|
+
|
36
|
+
def initial?
|
37
|
+
false
|
38
|
+
# @klass.aasm.initial_state == self.name
|
39
|
+
end
|
40
|
+
|
41
|
+
def final?
|
42
|
+
false
|
43
|
+
# !@klass.aasm.events.any? do |event|
|
44
|
+
# event.transitions.any? do |transition|
|
45
|
+
# transition.from == self.name
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Transitions::Event.class_eval do
|
52
|
+
def draw(graph)
|
53
|
+
@transitions.each do |transition|
|
54
|
+
graph.add_edge(transition.from.to_s.humanize, transition.to.to_s.humanize, label: name.to_s)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "graphviz"
|
2
|
+
|
3
|
+
module Transitions
|
4
|
+
class Graph < ::GraphViz
|
5
|
+
def initialize(class_name, options = {})
|
6
|
+
options = {path: '.'}.merge(options)
|
7
|
+
|
8
|
+
@file_path = File.join(options[:path], "#{class_name.parameterize('_')}_transitions.png")
|
9
|
+
super(:G)
|
10
|
+
end
|
11
|
+
|
12
|
+
def output
|
13
|
+
super png: @file_path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require "graphviz_transitions"
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphviz_transitions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Itkin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: transitions
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-graphviz
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gem patches Transitions to be able to generate graphs using GraphViz.
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- ".rspec"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- graphviz_transitions.gemspec
|
82
|
+
- lib/graphviz_transitions.rb
|
83
|
+
- lib/graphviz_transitions/railtie.rb
|
84
|
+
- lib/graphviz_transitions/version.rb
|
85
|
+
- lib/transitions/graph.rb
|
86
|
+
- spec/lib/graphviz_aasm_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage:
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.5.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Use Ruby-GraphViz for Transitions.
|
112
|
+
test_files:
|
113
|
+
- spec/lib/graphviz_aasm_spec.rb
|
114
|
+
- spec/spec_helper.rb
|