state_machines icon indicating copy to clipboard operation
state_machines copied to clipboard

Passing event kwargs to guards option

Open Eyvgeniy opened this issue 10 months ago • 1 comments

Add passing kwargs from event to guard

class Vehicle
  state_machine :state, initial: :parked do
    ...
    event :crash do
      transition all - [:parked, :stalled] => :stalled, if: ->(vehicle, kwargs) {kwargs[:arg] == true} # kwargs from event fire
    end
  end
end

vehicle = Vehicle.new
vehicle.crash(arg: false) # false

Eyvgeniy avatar Apr 21 '24 11:04 Eyvgeniy