Module: AASM::Vis
- Defined in:
- lib/aasm/vis.rb,
lib/aasm/vis/railtie.rb,
lib/aasm/vis/version.rb
Overview
Generates Mermaid state-diagram markdown for every AASM state machine registered in the host application. Mix into a class and call generate_markdown (the rake task does this) or build_diagrams to get the markdown as a string.
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
-
#build_diagrams(only: nil) ⇒ String
Builds the Mermaid markdown for the AASM state machines.
-
#generate_markdown(only: nil) ⇒ void
Writes the Mermaid markdown for the AASM state machines to
tmp/aasm-vis.md.
Instance Method Details
#build_diagrams(only: nil) ⇒ String
Builds the Mermaid markdown for the AASM state machines.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aasm/vis.rb', line 34 def build_diagrams(only: nil) filter = Array(only).map(&:to_s).reject(&:empty?) diagrams = [] AASM::StateMachineStore.stores.each do |klass_name, klass_store| next unless included?(klass_name, filter) klass = klass_name.safe_constantize klass_store.machine_names.each { |column| diagrams << diagram_for(klass, column) } end diagrams.join("\n\n") end |
#generate_markdown(only: nil) ⇒ void
This method returns an undefined value.
Writes the Mermaid markdown for the AASM state machines to tmp/aasm-vis.md.
20 21 22 23 24 25 26 |
# File 'lib/aasm/vis.rb', line 20 def generate_markdown(only: nil) Rails.application.eager_load! if defined?(Rails) path = File.join(Dir.pwd, "tmp", "aasm-vis.md") File.write(path, build_diagrams(only: only)) puts "File written to: #{path}" end |