GitXplorerGitXplorer
t

newflow

public
23 stars
3 forks
0 issues

Commits

List of commits on branch master.
Unverified
38e2d85027b3736a01f18e201d01745403784f26

Update the README

ttrotter committed 15 years ago
Unverified
f0f397fe74d169b4ffa26686defeb9b9d6732cbb

Better error reporting for invalid states

ttrotter committed 15 years ago
Unverified
d7afef152bce925de235c431b464e225bc276b65

Whoops

ttrotter committed 15 years ago
Unverified
06de78e5d030d1acb41d41ab6158228dfaeb1b11

Some cleanup

ttrotter committed 15 years ago
Unverified
9f10c7ba29f47d57e98baa289b020e29d4ce50d4

Fixing hidden bug that caused states to get reset

ttrotter committed 15 years ago
Unverified
387f840561580ca6bbd1cbae7f95c6ab6f533ed2

Don't overwrite existing workflow_state

ttrotter committed 15 years ago

README

The README file for this repository.

h1. Newflow

Newflow lets you decorate ruby classes with workflows. It also has a cool .dot generation tool for visualizing your workflows.

h2. Usage


  class OfficeWorker
    attr_accessor :boss, :phones
    attr_accessor :workflow_state  # Necessary unless you are using Rails
                                   # In Rails, create a workflow_state column in the db

    include Newflow

    define_workflow do
      state :at_work, :start => true do
        transitions_to :sleeping_under_desk, :unless => :boss_is_there?
        transitions_to :answering_phones, :if => :boss_is_there?
      end

      state :sleeping_under_desk do
        transitions_to :answering_phones, :if => :phones_are_ringing?
        transitions_to :going_home, :if => :after_five?, :trigger => :shutdown_computer
      end

      state :answering_phones do
        transitions_to :going_home, :if => :after_five?, :trigger => :shutdown_computer
      end

      state :going_home, :stop => true
    end

    def initialize
      @phones = []
    end

    def boss_is_there?
      !!boss
    end

    def phones_are_ringing?
      phones.detect { |p| p.ringing? }
    end

    def after_five?
      Time.now.hour >= 17
    end

    def shutdown_computer
      puts "shutdown -h now"
    end
  end

  office_worker = OfficeWorker.new
  office_worker.at_work?             # => true
  office_worker.transition!
  office_worker.to_dotty             # returns a .dot formatted string 
                                     #   that you can write to a 
                                     #   file and open with graphviz
  office_worker.sleeping_under_desk? # => true (because the boss wasn't there)

h2. Caveats

None! This thing is awesome!