GitXplorerGitXplorer
t

newflow

public
23 stars
3 forks
0 issues

Commits

List of commits on branch master.
Unverified
f9589265b1c371e435efdd19340ec19d067b50ff

Add would_transition_to

ttrotter committed 15 years ago
Unverified
0ec44982d4c5c75fc3b9163c0c36d624e967c26c

Treat ActiveRecord differently

ttrotter committed 15 years ago
Unverified
160992776dbd018e7e0ff01a632ec21ba1a15d7b

Always initialize the workflow state

ttrotter committed 15 years ago
Unverified
f84d74ee73888317a4f11c3764a65ca09529d01d

Get rid of the method missing

ttrotter committed 15 years ago
Unverified
73e8e547c9437f297f885983d993606b26ac3820

Add a convenience method for setting the state without executing any guards or triggers

ttrotter committed 15 years ago
Unverified
3c829113b815eaaaf4c75549685f0c0d7cd76518

Ignore package dir, update README, and let us make gems

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!