geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

Adds ability to select different adapters via a `workflow_adapter` class method. #111

Closed damncabbage closed 10 years ago

damncabbage commented 10 years ago

This PR:

From the included documentation change:

Other adapters (such as a custom ActiveRecord plugin) can be selected by adding a workflow_adapter class method, eg.

class Example
  def self.workflow_adapter
    MyCustomAdapter
  end
  include Workflow
  # ...
end

(The above will include MyCustomAdapter instead of Workflow::Adapter::ActiveRecord.)

damncabbage commented 10 years ago

Where am I going with this? I have an app-specific ActiveRecord adapter I'm working on (to handle record-locking to avoid race conditions, among other things), but the auto-inclusion in lib/workflow.rb prevents me from using it without forking the project entirely.

(I'm happy to have this closed if you don't feel it fits with the direction of the project.)

geekq commented 10 years ago

yes, this is the direction I would like to go too - enable custom AR persistence.

Will review after my computerless ;-) holiday - in a week...

damncabbage commented 10 years ago

Got it; thanks. :)

geekq commented 10 years ago

This is exactly the way I would implement the possibility for different persistent behaviours, e.g. persist new workflow state immediately on bang-method call (default) vs. later on save call. But never found time for that ;-) - thank you very much!

Also solves #77 - custom ActiveRecord adapter (persisting on save call) would help.