Giter Club home page Giter Club logo

state_machine_history's Introduction

state_machine_history

state_machine_history is an extension of the state_machine gem, that logs transitions between states and allows to check if a state was visited earlier.

Install

gem install state_machine_history

Ruby On Rails 2.x

Add the gem dependency to environment.rb:

...
config.gem 'state_machine_history'
...

Generate the migration:

script/generate state_machine_history_2 create_machine_history

Run the migration

rake db:migrate

Ruby On Rails 3

In Gemfile:

gem 'state_machine_history'

Generate the migration:

rails generate state_machine_history create_machine_history

Run the migration:

rake db:migrate

Usage

This gem adds logging function to the state_machine gem. Sample:

Class definition

class Order
  state_machine :initial => :not_selected do
    # Switch on state machine logging
    track_history

    event :choose do
      transition :not_selected => :selected
    end
    event :add_to_basket do
      transition :selected => :in_basket
    end
    event :pay do
      transition :in_basket => :paid
    end
    event :to_send do
      transition :paid => :sent
    end
  end
end

Using extensions

order = Order.new
# Perform transition (state change is logged)
order.choose
# Find whether order has visited not_selected state before selected one
order.was_there?(:not_selected, :selected) #=> true
# Find whether order has visited not_selected state before the current one
order.was_there?(:not_selected)  #=> true

Credits

Project Team

  • Mykhaylo Sorochan - Project Manager

  • Dmitriy Landberg - Software Developer

  • Nataliya Shatokhina - Tester

  • Sergey Mostovoy - Extension idea

Copyright © 2010 Sphere Consulting Inc., released under the MIT license (see LICENSE).

state_machine_history's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

smostovoy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.