Sha256: 1dc11b887ca4002868c5f54af787c789166550d71e6e6c036b7c1b1ef75fa772

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

= transitions

The gem is based on Rick Olson's code of ActiveModel::StateMachine,
axed from ActiveModel in {this
commit}[http://github.com/rails/rails/commit/db49c706b62e7ea2ab93f05399dbfddf5087ee0c].

== 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

== Usage

Krzysiek Heród (aka {Netizer}[http://github.com/netizer]) wrote a nice {blog
post}[http://dev.netizer.pl/transitions-state-machine-for-rails-3.html]
about using Transitions in ActiveRecord.

== Copyright

Copyright (c) 2010 Jakub Kuźma. See LICENSE for details.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
transitions-0.0.9 README.rdoc