11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/aasm/vis.rb', line 11
def generate_markdown
Rails.application.eager_load! if defined?(Rails)
results = []
AASM::StateMachineStore.stores.each do |klass_name, klass_store|
klass_store.keys.each do |column|
transitions = []
klass = klass_name.safe_constantize
klass.aasm(column).events.each do |event|
event.name
event.default_display_name
event.transitions.each do |transition|
transitions << [transition.from, transition.to]
end
end
results << <<~TXT
```mermaid
---
title: #{klass}##{column}
---
stateDiagram-v2
#{klass.aasm(column).states.map { |state| "#{state.name} : #{state.default_display_name}" }.join("\n") }
#{transitions.map { |from, to| "#{from.nil? ? "[*]" : from } --> #{to}" }.join("\n") }
#{transitions.map { |_from, to| "#{to} --> [*]" if transitions.none? { |t| t[0] == to } }.reject(&:nil?).join("\n")}
```
TXT
end
end
path = File.join(Dir.pwd,'tmp', 'assm-vis.md')
results = results.join("\n\n")
File.write(path, results)
puts "File written to: #{path}"
end
|