3

My problem is that I have an application that gives a user the ability to define a workflow (states, transitions, events, etc.) and have my application know how it reacts (transitions) based on the users workflow.

I have looked at several state machine gems, such as AASM, and I see how I could use the gem to pre-define the state machine but if the state machine needed to change, it looks like I would have to modify the code and re-deploy. I have been arguing with my coworker about how we could / could not utilize a state machine gem to do what we want but, to me, they all seem to define a static state machine and changes to that state machine require code changes.

His suggestion is dynamically modifying the Ruby class to match the users workflow changes. My thought is that the states, transitions, events, guards, etc. are persistable objects that the user modifies through the our API. Neither of our current lines of thought seem to work with the current Ruby state machines without some major modification on top of those gems.

The place I keep looking at as an example solution is JIRA and how you can define states, transitions, and other workflow attributes for a project dynamically.

Jon
  • 743
  • 8
  • 21
  • I briefly looked at the AASM gem, and it looks like state machine rules are stored in classes. Couldn't you just make a new class every time the state machine rules change? – Adrian Jan 04 '15 at 19:27
  • Dynamically, that is. (Sorry for the extra comment, this website won't let me edit comments for some reason) – Adrian Jan 04 '15 at 19:33
  • That seems to be one of the arguments. We create a config file or object that defines the state machine and that gets translated into a dynamic Ruby class that can be interpreted by AASM (or whatever state machine). The other half of the argument is to model the state machine classes so they can be persisted and have those objects be used to drive the state machine. We don't really know the best way to do this but all state machine gems seem to want the state machine statically defined and only persist the current state of an object. – Jon Jan 05 '15 at 00:23
  • http://stackoverflow.com/questions/31911077/ror-workflow-gem-i-want-to-implement-dynamic-states-from-database – illusionist Aug 18 '15 at 23:42

2 Answers2

0

State machine should be used when business logic is pre-defined, otherwise you should model it in different way. If you want users to create their own workflow (e.g. states, transitions, events), then it would make sense to create separate models for state, transition and event, and define their relationships in code.

Then you can have, say, several kinds of transitions and events, that have different outcomes. If you could describe in detail what kind of dynamic workflow you need I could tell you more — working on similar project right now, though we haven't introduced events and transitions to the workflow yet

Alex Ponomarev
  • 745
  • 3
  • 10
0

The state_machine gem allows this:

https://github.com/pluginaweek/state_machine#static--dynamic-definitions

Aristata
  • 600
  • 2
  • 8
  • 17
  • That gem definitely is close to what I'm looking for but the development on that dried up a long time ago. Something else that has since caught my attention is this gem, [rails_workflow](https://github.com/madzhuga/rails_workflow). I have not actually used it yet, but it seemed like it was the closest fit to my use case. – Jon Aug 19 '15 at 22:23