Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

locaweb/bpmachine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bpmachine

bpmachine is a ruby gem created to act as a state machine for the application in order to control each status of whole process.

It was made to work with activerecord but it will work with any class that implements the save! method.

How to use it

Add it to your Gemfile

gem "bpmachine"

Include the ProcessSpecification module in your class:

class MyClass
  include ProcessSpecification
end

Define your process

include ProcessSpecification
process :of => :anything do
  transition :some_event, :from => :initial, :to => :final
end

The gem will look for a AnythingSteps in the app/steps directory and run the some_event method, changing the object status of MyClass from :initial to :final.

Add callbacks

  • around: called around each transition
  • after_processes: called at the end of the workflow
class MyClass
  include ProcessSpecification

  after_processes do |instance|
    puts 'All is done'
  end

  around do |transition, instance, block|
    logger.tagged transition[:method] do
      logger.info "Going from #{instance.status} to #{transition[:target]}"
      block.call
    end
  end
end

Contributors

Copyright

Copyright (c) 2016 Locaweb. See LICENSE for details.

About

Includes a DSL for business process specification. The process state is persistent, which allows it to be be resumed if an error occurs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages