statecraft 0.2.0 → 0.3.0
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 +4 -4
- data/README.md +14 -0
- data/lib/statecraft/diagram.rb +18 -0
- data/lib/statecraft/machine.rb +1 -0
- data/lib/statecraft/version.rb +1 -1
- data/lib/statecraft.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a49958ae3b97e963ada9ee0cb6f719bd0fa5a784704d7f1479f0b045a921ec1
|
|
4
|
+
data.tar.gz: e6fe7115b639e25d33e752800af3324822497413865236be7f53e01dc56674bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92730425ebca1937db4f9e53bac01020102a7c6c90bc76fd5518697394bec18720cb70dd826017ca9b36d4e873cd0817a6399399565098e0dfc687db853ad68b
|
|
7
|
+
data.tar.gz: f7511de223aa42b0f44c5fc0b14a0be53965887262b01bb62c9a1954abb9e4e98b4a2b5688ee967ca672cd19514ddc2357fbcd796139074612ee2ac588975357
|
data/README.md
CHANGED
|
@@ -222,6 +222,7 @@ order.offerable_events # => [:pay, :cancel] — grap
|
|
|
222
222
|
order.refusals_for(:cancel) # => [#<event: :cancel, guard: :customer_cancellable?, layer: :event_record>]
|
|
223
223
|
order.transitioned_to?(:paid) # strictly log-based
|
|
224
224
|
OrderFlow.transitions_from(:pending) # => [{ to: :paid, events: [:pay] }, ...]
|
|
225
|
+
OrderFlow.to_mermaid # the graph as Mermaid stateDiagram-v2 text
|
|
225
226
|
```
|
|
226
227
|
|
|
227
228
|
`transitions_from` is class-level and answers the graph's shape, not a
|
|
@@ -229,6 +230,19 @@ prediction: no guards are consulted, a bare edge carries an empty `events`
|
|
|
229
230
|
list, and a state outside the graph owns no edges. Pair it with
|
|
230
231
|
`available_transitions` for the prediction.
|
|
231
232
|
|
|
233
|
+
The shape also draws itself: `to_mermaid` returns the graph as Mermaid
|
|
234
|
+
`stateDiagram-v2` text — guards stay out of the picture, exactly like
|
|
235
|
+
`transitions_from`. Paste it into a markdown fence and GitHub renders the
|
|
236
|
+
diagram; the quick-start machine above comes out as:
|
|
237
|
+
|
|
238
|
+
<!-- illustrative -->
|
|
239
|
+
```mermaid
|
|
240
|
+
stateDiagram-v2
|
|
241
|
+
[*] --> pending
|
|
242
|
+
pending --> paid : pay
|
|
243
|
+
pending --> cancelled
|
|
244
|
+
```
|
|
245
|
+
|
|
232
246
|
`available_transitions` tells you not only *where* you can go but *how*:
|
|
233
247
|
`via` lists the events whose guards pass, plus `:direct` when the edge is
|
|
234
248
|
free of event guards and its edge guards pass. Every answer is a snapshot —
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Statecraft
|
|
4
|
+
# Renders the compiled graph as Mermaid stateDiagram-v2 text: the states,
|
|
5
|
+
# the initial marker and event-labeled edges in declaration order. The
|
|
6
|
+
# shape only — like transitions_from, no guards are consulted or rendered.
|
|
7
|
+
module Diagram
|
|
8
|
+
def to_mermaid
|
|
9
|
+
graph = finalize!
|
|
10
|
+
lines = ["stateDiagram-v2", " [*] --> #{graph.initial_state}"]
|
|
11
|
+
graph.edges.each_value do |edge|
|
|
12
|
+
arrow = " #{edge.from} --> #{edge.to}"
|
|
13
|
+
lines << (edge.event_names.empty? ? arrow : "#{arrow} : #{edge.event_names.join(" / ")}")
|
|
14
|
+
end
|
|
15
|
+
"#{lines.join("\n")}\n"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/statecraft/machine.rb
CHANGED
data/lib/statecraft/version.rb
CHANGED
data/lib/statecraft.rb
CHANGED
|
@@ -13,6 +13,7 @@ require_relative "statecraft/pipeline/edge_resolution"
|
|
|
13
13
|
require_relative "statecraft/pipeline"
|
|
14
14
|
require_relative "statecraft/pipeline/surface"
|
|
15
15
|
require_relative "statecraft/introspection"
|
|
16
|
+
require_relative "statecraft/diagram"
|
|
16
17
|
require_relative "statecraft/mounting"
|
|
17
18
|
|
|
18
19
|
ActiveSupport.on_load(:active_record) do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: statecraft
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Igor Pugachev
|
|
@@ -70,6 +70,7 @@ files:
|
|
|
70
70
|
- lib/generators/statecraft/machine/templates/model.rb.tt
|
|
71
71
|
- lib/generators/statecraft/machine/templates/namespace_module.rb.tt
|
|
72
72
|
- lib/statecraft.rb
|
|
73
|
+
- lib/statecraft/diagram.rb
|
|
73
74
|
- lib/statecraft/errors.rb
|
|
74
75
|
- lib/statecraft/instrumentation.rb
|
|
75
76
|
- lib/statecraft/introspection.rb
|