state-machines / state_machines

Adds support for creating state machines for attributes on any Ruby class
https://github.com/state-machines/state_machines
MIT License
814 stars 91 forks source link

Possible events calculation #71

Closed nir0 closed 5 years ago

nir0 commented 5 years ago

first issue is to show buttons for available events with the object. so, i solved it with code:

.actions
  -@mission.state_paths(from: @mission.state, deep: false, guard: false).map{|a|a[0]}.uniq.map(&:event).map do |event|
    -begin
      =render "#{event.to_s}", mission: @mission, formats: [:html]
    -rescue
      =button event.to_s, '#', disabled: true

it works just fine until i add loops into events logic, for example, active mission can have event "take" which doesn't switch state, or some actions allow going back in actions. state_paths returns thousands of variants and takes several seconds, which makes it unusable

is there any method to quickly calculate next possible event?

nir0 commented 5 years ago

solved with state_transitions