workflow icon indicating copy to clipboard operation
workflow copied to clipboard

Callback on entering initial state

Open penguoir opened this issue 3 years ago • 1 comments

I'd like to run a callback when an object enters its initial state. For example:

class Article
  include Workflow

  workflow do
    state :new
  end

  def on_new_entry
    puts 'entered new'
  end
end

Currently, workflow doesn't run the on_new_entry callback. Is this expected? If so, what's the best practice for running a callback on entering of an initial state?

penguoir avatar Jul 21 '22 12:07 penguoir

Looking at https://github.com/geekq/workflow/blob/ba6946ba6711e2d255cc2fd5d28e6af3add3df36/lib/workflow.rb#L97, on entry is not called for the initial action, only when transitioning from one action to another.

I'd suggest defining a method with the state name, but that's tricky with an event called 'new'. You could always call it something else, like 'initial', and then you could have an initial method?

tlloydthwaites avatar Mar 07 '24 03:03 tlloydthwaites