GitXplorerGitXplorer
t

newflow

public
23 stars
3 forks
0 issues

Commits

List of commits on branch master.
Unverified
ab3a8217602ddf8dcaa2efe554bbbdcee3a02a03

Merge pull request #1 from relaynetwork/master

ttrotter committed 14 years ago
Unverified
fcda1589bf7c979d9e58c320f38070e21bce004e

allow self-transition

committed 14 years ago
Unverified
2639abf6be6f894d974d97d850b96d0801220d8c

Add on_entry to states

ttrotter committed 15 years ago
Unverified
376b361b61515c6a408bb969e2a0ab442d191d46

Adding some TODOs

ttrotter committed 15 years ago
Unverified
e2598e87d9fe1e9340c762f001ffbf9bc89f9c22

Oh yea, FileList is only available in rake... sorry github

ttrotter committed 15 years ago
Unverified
1a4472727174ed5b9c803c47b25703fb131a86f6

Do the gemspec the github way

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!