graphviz_aasm 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 689c7a59230667068094f130a38eff5af5282a21
4
+ data.tar.gz: c7bbb0d0dc62f3c29acfe865ef2dc5dc00020660
5
+ SHA512:
6
+ metadata.gz: 9c48c61e4e3b619e7c31149a7542b521ca384f0794f3d43222636c34a355983dbe14c9fcd6db3e32689ae01e28d0a8bed859f554f66ad31a86b9cd51adf4c404
7
+ data.tar.gz: fc3fd2e310f2a0151b310854a73c607323b9e02705a75b4e1458f48a9d2b2c87435bee5d25ab4fdabb65b67f7c4749d8f96a1c6a6fe923aa6285974564b9f246
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .idea
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in graphviz_aasm.gemspec
4
+ gemspec
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,38 @@
1
+ # GraphvizAasm
2
+
3
+ Adds support for generating graphs based on states, events and transitions defined for AASM 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_aasm'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install graphviz_aasm
20
+
21
+ ## Usage
22
+
23
+ To generate a graph for a specific model:
24
+
25
+ $ rake aasm: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/romatr/graphviz_aasm/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
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'graphviz_aasm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "graphviz_aasm"
8
+ spec.version = GraphvizAasm::VERSION
9
+ spec.authors = ["Roman Trofimov"]
10
+ spec.email = ["trofimov.roman@gmail.com"]
11
+ spec.summary = %q{Use Ruby-GraphViz for AASM.}
12
+ spec.description = %q{This gem patches AASM to be able to generate graphs using GraphViz.}
13
+ spec.homepage = "https://github.com/romatr/graphviz_aasm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 10.2.1"
23
+ spec.add_development_dependency "rspec", "~> 2.14.1"
24
+
25
+ spec.add_dependency "aasm", "~> 3.1.1"
26
+ spec.add_dependency "rails", "~> 4.0.4"
27
+ spec.add_dependency "ruby-graphviz", "~> 1.0.9"
28
+ end
data/lib/aasm/graph.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "graphviz"
2
+
3
+ module AASM
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('_')}_aasm.png")
9
+ super(:G)
10
+ end
11
+
12
+ def output
13
+ super png: @file_path
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,55 @@
1
+ require "aasm"
2
+ require "aasm/graph"
3
+ require "graphviz_aasm/version"
4
+
5
+ module GraphvizAasm
6
+ require "graphviz_aasm/railtie" if defined?(Rails)
7
+
8
+ AASM::StateMachine.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 = AASM::Graph.new(class_name, options)
16
+
17
+ klass.aasm.states.each do |state|
18
+ state.draw(graph)
19
+ end
20
+
21
+ klass.aasm.events.each_value do |event|
22
+ event.draw(graph)
23
+ end
24
+ graph.output
25
+ end
26
+ end
27
+ end
28
+
29
+ AASM::State.class_eval do
30
+ def draw(graph)
31
+ node = graph.add_nodes(self.human_name, shape: final? ? "doublecircle" : "ellipse")
32
+ graph.add_edge(graph.add_nodes("starting_state", shape: "point"), node) if initial?
33
+ end
34
+
35
+ def initial?
36
+ @clazz.aasm.initial_state == self.name
37
+ end
38
+
39
+ def final?
40
+ !@clazz.aasm.events.any? do |_, event|
41
+ event.transitions.any? do |transition|
42
+ transition.from == self.name
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ AASM::Event.class_eval do
49
+ def draw(graph)
50
+ transitions.each do |transition|
51
+ graph.add_edge(transition.from.to_s.capitalize, transition.to.to_s.capitalize)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,9 @@
1
+ module GraphvizAasm
2
+ class Railtie < Rails::Railtie
3
+ railtie_name :graphviz_aasm
4
+
5
+ rake_tasks do
6
+ load "tasks/graphviz_aasm.rake"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module GraphvizAasm
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,10 @@
1
+ namespace :aasm do
2
+ desc "Draws AASM states using GraphViz (options: CLASS=User,Vehicle; TARGET=/folder/path ; ORIENTATION=portrait;)"
3
+ task draw: :environment do
4
+ options = {}
5
+ options[:path] = ENV['TARGET'] if ENV['TARGET']
6
+ options[:orientation] = ENV['ORIENTATION'] if ENV['ORIENTATION']
7
+
8
+ AASM::StateMachine.draw(ENV['CLASS'], options)
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe GraphvizAasm do
4
+ pending
5
+ end
@@ -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_aasm"
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,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphviz_aasm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Trofimov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-28 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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.2.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: aasm
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.0.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.0.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-graphviz
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.9
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.9
97
+ description: This gem patches AASM to be able to generate graphs using GraphViz.
98
+ email:
99
+ - trofimov.roman@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - graphviz_aasm.gemspec
111
+ - lib/aasm/graph.rb
112
+ - lib/graphviz_aasm.rb
113
+ - lib/graphviz_aasm/railtie.rb
114
+ - lib/graphviz_aasm/version.rb
115
+ - lib/tasks/graphviz_aasm.rake
116
+ - spec/lib/graphviz_aasm_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/romatr/graphviz_aasm
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.1.11
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Use Ruby-GraphViz for AASM.
142
+ test_files:
143
+ - spec/lib/graphviz_aasm_spec.rb
144
+ - spec/spec_helper.rb