katee / aasm-diagram Goto Github PK
View Code? Open in Web Editor NEWGenerate diagrams of AASM state machines.
Generate diagrams of AASM state machines.
Very cool project - I wonder if there's a simple way to adjust the amount of space between the lines and the transition names?
In some diagrams things have looked a bit crowded
maybe just prefix the transition name with a couple of whitespaces?
At least in my experience just now, on rails 7
Given two classes:
class Test
include ::AASM
class LocalStatusEnum < EnumerateIt::Base
associate_values(
:my_first_state,
:my_second_state
)
end
class LocalEventEnum < EnumerateIt::Base
associate_values(
:my_one_event,
:my_other_event
)
end
aasm do
state LocalStatusEnum::MY_FIRST_STATE.to_sym
state LocalStatusEnum::MY_SECOND_STATE.to_sym
event LocalEventEnum::MY_ONE_EVENT.to_sym do
transitions(
from: LocalStatusEnum::MY_FIRST_STATE.to_sym,
to: LocalStatusEnum::MY_SECOND_STATE.to_sym
)
end
end
end
and
class TestSub < Test
aasm do
state :my_third_state
event LocalEventEnum::MY_OTHER_EVENT.to_sym do
transitions(
from: LocalStatusEnum::MY_SECOND_STATE.to_sym,
to: :my_third_state
)
end
end
end
require 'aasm-diagram'
test = TestSub.new
AASMDiagram::Diagram.new(test.aasm, 'test.png')
produces
even though I can transition to my_third_state:
[3] DEVELOPMENT(main)> test.my_first_state?
=> true
[4] DEVELOPMENT(main)> test.may_my_one_event?
=> true
[5] DEVELOPMENT(main)> test.may_my_other_event?
=> false
[6] DEVELOPMENT(main)> test.my_one_event
=> true
[7] DEVELOPMENT(main)> test.may_my_other_event?
=> true
[8] DEVELOPMENT(main)> test.my_other_event
=> true
[9] DEVELOPMENT(main)> test.my_third_state?
=> true
If I transition to my_second_state BEFORE diagramming, I get the correct diagram
We wanted to generate the state transition diagram only for 1 of my guard conditions as we have multiple guard conditions and we don't want the diagram for all the guard condition transition.
event :move_to_abc do
transitions from: :xyz, to: :abc, guards: :guard1?
transitions from: :mno, to: :abc, guards: :guard2?
transitions from: :pqr, to: :abc, guards: :guard3?
end
So we have to generate different diagram for every guards i.e. guard1, guard2, guard3
Hi. First, thank you for this great gem.
I thought it would be useful if lib/aasm_diagram/railtie.rb
is created, and in there, define the rake task for generating the png file, using the AASMDiagram::Diagram.new(ModelName.new.aasm, Rails.root / (ModelName) + '.png' )
. I think the synopsis of such command will be something like: rake aasm:diagram[ModelName]
. Since it will be defined as a railtie, those who are not using rails will not be affected.
Any opinion?
If this sounds good, I can implement it and create such PR.
2.4.0 :182 > AASMDiagram::Diagram.new(rfq.aasm, 'Bug.png')
NoMethodError: undefined method `id' for nil:NilClass
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/ruby-graphviz-1.2.3/lib/graphviz/edge.rb:196:in `getNodeNameAndPort'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/ruby-graphviz-1.2.3/lib/graphviz/edge.rb:31:in `initialize'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/ruby-graphviz-1.2.3/lib/graphviz.rb:210:in `new'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/ruby-graphviz-1.2.3/lib/graphviz.rb:210:in `add_edges'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/aasm-diagram-0.1.0/lib/aasm_diagram/diagram.rb:30:in `block (2 levels) in draw_edges'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/aasm-diagram-0.1.0/lib/aasm_diagram/diagram.rb:26:in `each'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/aasm-diagram-0.1.0/lib/aasm_diagram/diagram.rb:26:in `block in draw_edges'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/aasm-diagram-0.1.0/lib/aasm_diagram/diagram.rb:25:in `each'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/aasm-diagram-0.1.0/lib/aasm_diagram/diagram.rb:25:in `draw_edges'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/aasm-diagram-0.1.0/lib/aasm_diagram/diagram.rb:15:in `draw'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/aasm-diagram-0.1.0/lib/aasm_diagram/diagram.rb:8:in `initialize'
from (irb):182:in `new'
from (irb):182
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/railties-5.0.6/lib/rails/commands/console.rb:65:in `start'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/railties-5.0.6/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/railties-5.0.6/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/railties-5.0.6/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/ahmadyakobbinabaidullah/.rvm/gems/ruby-2.4.0@eproc/gems/railties-5.0.6/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.