statesman-diagram 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a197c2d36873e26b2de620f97d8180782b059a8
4
- data.tar.gz: 5ea01f31f7fc7658e1fb9f6191b95c9367ac1a5c
3
+ metadata.gz: 16343a14d2db965949cd03525930344782e89c63
4
+ data.tar.gz: 1482e56175e597d5e09c2546f81233e76ce933a5
5
5
  SHA512:
6
- metadata.gz: 88eb555e1a56c21c2b406d6d7b283d67c5347243897254e664d80dc67763dab2d5a8d7268011bb9715de60f9e10eb83d936d3a4ad1421beec0c703fa67a406a7
7
- data.tar.gz: 27f358220e8c5632b44732ff028dfccd00d33db77b9770c577d320c1a68f4c94d58ebc9ec257825ff1b09cd3ec9b2685d4e6c0dfd62595f942b8b6cd18103225
6
+ metadata.gz: b19dde9ff759e4bb95c54165a34e201d3c80c454909cee982766f36034d8e2ddfc1a91f364d06ffd4a3617a11faa33d12064b1d03a775931d3ca68a0e8e86fec
7
+ data.tar.gz: eda071f3eb579a75be5c0ff4b5d4f6cc0e961976469b829f0ae620ca51548824f91c4cd32333028785f14efe068df9325e16617297d71a95a5d7222c83996287
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in statesman-diagram.gemspec
4
3
  gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ statesman-diagram (0.1.2)
5
+ statesman (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.6.0)
13
+ rspec-core (~> 3.6.0)
14
+ rspec-expectations (~> 3.6.0)
15
+ rspec-mocks (~> 3.6.0)
16
+ rspec-core (3.6.0)
17
+ rspec-support (~> 3.6.0)
18
+ rspec-expectations (3.6.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.6.0)
21
+ rspec-mocks (3.6.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.6.0)
24
+ rspec-support (3.6.0)
25
+ statesman (2.0.1)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.14)
32
+ rake (~> 10.0)
33
+ rspec (~> 3.0)
34
+ statesman-diagram!
35
+
36
+ BUNDLED WITH
37
+ 1.15.4
data/README.md CHANGED
@@ -40,7 +40,10 @@ Or install it yourself as:
40
40
  ## Usage
41
41
 
42
42
  Run `rake statesman:diagram[My::State::Machine::Class]`.
43
- Find the state diagram of this class in `My::State::Machine::Class.png`.
43
+ Find the state diagram of this class in `My_State_Machine_Class.png`.
44
+
45
+ You can also specify the name of the file `rake statesman:diagram[My::State::Machine::Class, ./temp/state]`
46
+ Find the state diagram of this class in `./temp/state.png`.
44
47
 
45
48
  ## Development
46
49
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
@@ -1,15 +1,2 @@
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
1
+ require 'statesman/machine/class_methods'
2
+ require 'statesman/diagram'
@@ -0,0 +1,49 @@
1
+ require 'open3'
2
+
3
+ module Statesman
4
+ class Diagram
5
+ # @param [String] name - name of the diagram.
6
+ # @param [Hash] graph - list of vertices and edges.
7
+ def initialize(name:, graph:)
8
+ @name = name
9
+ @graph = graph
10
+ end
11
+
12
+ # @return [String] diagram in DOT format.
13
+ def to_dot
14
+ format("digraph %{name} {\n %{body}\n}", name: @name, body: dot_body.join("\n "))
15
+ end
16
+
17
+ def to_png(file_name = nil)
18
+ file_name ||= @name
19
+ file_name += '.png'
20
+
21
+ build_png(file_name)
22
+ end
23
+
24
+ private
25
+
26
+ # @return [String]
27
+ def dot_body
28
+ @graph.map do |vertex, edges|
29
+ edges.map do |to|
30
+ "#{vertex} -> #{to};"
31
+ end
32
+ end.flatten
33
+ end
34
+
35
+ def build_png(file_name)
36
+ cmd = ['dot', '-Tpng', "-o#{file_name}"]
37
+
38
+ puts "Running '#{cmd.join(' ')}' with this ^ as stdin..."
39
+
40
+ output, status = Open3.capture2e(*cmd, stdin_data: to_dot)
41
+ if status.success?
42
+ puts "Success. You can open #{file_name} and see the diagram."
43
+ else
44
+ puts 'The command failed:'
45
+ puts output
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Statesman
2
+ class Diagram
3
+ VERSION = '0.1.2'.freeze
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'statesman/machine'
2
+
3
+ module Statesman
4
+ module Machine
5
+ module ClassMethods
6
+ # @return [Statesman::Diagram] diagram for the state machine
7
+ def diagram
8
+ Diagram.new(name: name.gsub('::', '_'), graph: successors)
9
+ end
10
+
11
+ # @return [String] state machine in DOT format.
12
+ def to_dot
13
+ diagram.to_dot
14
+ end
15
+
16
+ def to_png(file_name = nil)
17
+ diagram.to_png(file_name)
18
+ end
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statesman-diagram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Vassilevsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: statesman
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
20
- type: :development
19
+ version: '2.0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '1.14'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '1.14'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: statesman
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
62
- type: :runtime
61
+ version: '3.0'
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '3.0'
69
69
  description:
70
70
  email:
71
71
  - vassilevsky@gmail.com
@@ -73,15 +73,15 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
77
- - ".vexor.yml"
78
76
  - Gemfile
77
+ - Gemfile.lock
79
78
  - LICENSE.txt
80
79
  - README.md
81
80
  - Rakefile
82
81
  - lib/statesman-diagram.rb
83
- - lib/tasks/statesman.rake
84
- - statesman-diagram.gemspec
82
+ - lib/statesman/diagram.rb
83
+ - lib/statesman/diagram/version.rb
84
+ - lib/statesman/machine/class_methods.rb
85
85
  homepage: https://github.com/vassilevsky/statesman-diagram
86
86
  licenses:
87
87
  - MIT
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.vexor.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.3.3
5
- - 2.2.6
6
- - 2.1.9
7
-
8
- before_install:
9
- - sudo apt-get update -yq && sudo apt-get install -y graphviz
10
- - gem install bundler -v 1.14.4
@@ -1,21 +0,0 @@
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.name.gsub('::','_')}.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
@@ -1,27 +0,0 @@
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.1"
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