statesman-diagram 0.1.0
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 +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/lib/statesman-diagram.rb +15 -0
- data/lib/tasks/statesman.rake +21 -0
- data/statesman-diagram.gemspec +27 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca3590ccc9a8e59faa1f476fdc5040cf6042581f
|
4
|
+
data.tar.gz: 21044a3ad7fb2512fe29d110655bf97dd2dcd84f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efb8318d957ef1f33ab03c49528a2b222e670d2b9bf2547974eda61af68037503a7f6a148917c2bc37ccf0081afb8d95d23a847ba9c9b69e8053e35bb165127a
|
7
|
+
data.tar.gz: 8498622a278ed83a5870f291aa18193dbc94d333b6673bc848b0609bb060c7a8514db75a63c674a28c4fd646a344ee94cba5a469cce8922b49ef087dcdd9c935
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ilya Vassilevsky
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Statesman State Diagram
|
2
|
+
|
3
|
+
Adds `.to_dot` method to `Statesman::Machine`. It can export your machine
|
4
|
+
class definition to the
|
5
|
+
[DOT](https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29) format.
|
6
|
+
|
7
|
+
Also adds a Rake task called `statesman:diagram`. It runs the `dot`
|
8
|
+
program (GraphViz) to make a PNG image from the DOT representation of the
|
9
|
+
machine class.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
group :development do
|
17
|
+
gem 'statesman-diagram'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install statesman-diagram
|
28
|
+
|
29
|
+
## Prerequisites
|
30
|
+
|
31
|
+
* GraphViz (the `dot` program)
|
32
|
+
* `brew install graphviz` on OS X / macOS
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Run `rake statesman:diagram[My::State::Machine::Class]`.
|
37
|
+
Find the state diagram of this class in `My::State::Machine::Class.png`.
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vassilevsky/statesman-diagram.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "statesman/machine"
|
2
|
+
|
3
|
+
module Statesman
|
4
|
+
module Machine
|
5
|
+
module ClassMethods
|
6
|
+
def to_dot
|
7
|
+
<<-DOT
|
8
|
+
digraph #{name.gsub('::', '_')} {
|
9
|
+
#{successors.map{|from, tos| tos.map{|to| " #{from} -> #{to};" } }.flatten.join("\n")}
|
10
|
+
}
|
11
|
+
DOT
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :statesman do
|
2
|
+
desc "Render a PNG image of the state diagram of the given state machine class"
|
3
|
+
task :diagram, [:class] => :environment do |t, args|
|
4
|
+
machine_class = self.class.const_get(args[:class])
|
5
|
+
puts "Will draw the state diagram of #{machine_class}"
|
6
|
+
dot = machine_class.to_dot
|
7
|
+
puts "Here it is in the textual form:"
|
8
|
+
puts dot
|
9
|
+
filename = "#{machine_class}.png"
|
10
|
+
cmd = %W(dot -Tpng -o#{filename})
|
11
|
+
puts "Running '#{cmd.join(' ')}' with this ^ as stdin..."
|
12
|
+
require 'open3'
|
13
|
+
output, status = Open3.capture2e(*cmd, stdin_data: dot)
|
14
|
+
if status.success?
|
15
|
+
puts "Success. You can open #{filename} and see the diagram."
|
16
|
+
else
|
17
|
+
puts 'The command failed:'
|
18
|
+
puts output
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "statesman-diagram"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["Ilya Vassilevsky"]
|
9
|
+
spec.email = ["vassilevsky@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Generates DOT representations of Statesman machines and runs dot to render them to PNGs"
|
12
|
+
spec.homepage = "https://github.com/vassilevsky/statesman-diagram"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "statesman", "~> 2.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: statesman-diagram
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya Vassilevsky
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-15 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: statesman
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- vassilevsky@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/statesman-diagram.rb
|
82
|
+
- lib/tasks/statesman.rake
|
83
|
+
- statesman-diagram.gemspec
|
84
|
+
homepage: https://github.com/vassilevsky/statesman-diagram
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.5.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Generates DOT representations of Statesman machines and runs dot to render
|
108
|
+
them to PNGs
|
109
|
+
test_files: []
|