Sha256: f8a2da41913abe60c89eade54d2b4bbe0322013d10a22652adb6ecc9a9e0c06a

Contents?: true

Size: 623 Bytes

Versions: 4

Compression:

Stored size: 623 Bytes

Contents

require "microfsm"

# This example can be run with ruby -I lib/ ./examples/advanced.rb

fsm = MicroFSM.new(:pending)
proc = ->(event) { puts fsm.state.capitalize }
fsm.when(:confirm, pending: :confirmed, &proc)
  .when(:ignore, pending: :ignored, &proc)
  .when(:reset, confirmed: :pending, ignored: :pending, &proc)

puts "Should print Confirmed, Pending and Ignored:"
fsm.trigger(:confirm)
fsm.trigger(:ignore)
fsm.trigger(:reset)
fsm.trigger(:ignore)

puts "Should print all states: confirmed, ignored, pending"
puts fsm.states.join ", "

puts "Should print all events: confirm, ignore, reset"
puts fsm.events.join ", "

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
microfsm-0.1.10 examples/advanced.rb
microfsm-0.1.7 examples/advanced.rb
microfsm-0.1.6 examples/advanced.rb
microfsm-0.1.4 examples/advanced.rb