Closed tlloydthwaites closed 1 month ago
Thanks for your contribution! This pull request contains two unrelated things:
before_transition
, on_error
, on_entry
etc. in addition to blocks also support methods by naming conventionFor the first one I have no objections except minor incompatibility issue in case somebody defined e.g. an on_error
method to do something unrelated to workflow
. Formally we would need to wait until a major 4.0 release and add some deprecation warning already. Or maybe use more specific method names like on_workflow_error
instead of on_error
, where it is more unlikely for somebody to already have such a method for a different purpose. After carefully considering pros and contra, I would stick with existing functionality for now.
For the second part, I think it brings a lot of additional complexity to the very core of workflow
by storing symbols instead of Procs sometimes.
Dynamically composing workflow definition from a json file, could be useful for some people though. Thank you for providing an extensive example! The desired result can be achieved with existing features of workflow
, without changes to the library like that: https://github.com/geekq/workflow/blob/develop/test/workflow_from_json_test.rb
I started with your original test file and made some minor adjustments to take advantage of the existing workflow
model.
When building a workflow spec dynamically we can't specify procs, but we can specify symbols for methods we want to run.
This PR allows us to specify a symbol when calling
on_entry
andon_exit
.It also tries to call
before_transition
,on_transition
,after_transition
, andon_error
as methods on the workflow object as well as using the standard procs.