Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

State machine extracted from ActiveModel

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 transitions.gemspec
README.rdoc

transitions

The gem is based on Rick Olson's code of ActiveModel::StateMachine, axed from ActiveModel in this commit.

Installation

If you're using Rails + ActiveRecord + Bundler

# in your Gemfile
gem "transitions", :require => ["transitions", "active_record/transitions"]

# in your AR models that will use the state machine
include ::Transitions
include ActiveRecord::Transitions

state_machine do
  state :available # first one is initial state
  state :out_of_stock
  state :discontinue

  event :discontinue do
    transitions :to => :discontinue, :from => [:available, :out_of_stock], :on_transition => :do_discontinue
  end
  event :out_of_stock do
    transitions :to => :out_of_stock, :from => [:available, :discontinue]
  end
  event :available do
    transitions :to => :available, :from => [:out_of_stock], :on_transition => :send_alerts
  end
end

Copyright

Copyright © 2010 Jakub Kuźma. See LICENSE for details.

Something went wrong with that request. Please try again.