<commit_before># Big machine [![Build Status](https://secure.travis-ci.org/alaibe/big_machine.png)][travis] [![Dependency Status](https://gemnasium.com/alaibe/big_machine.png)][gemnasium] [![Code Climate](https://codeclimate.com/badge.png)][codeclimate]

[travis]: http://travis-ci.org/alaibe/big_machine
[gemnasium]: https://gemnasium.com/alaibe/big_machine
[codeclimate]: https://codeclimate.com/github/alaibe/big_machine

Big machine is a Gem which give state to your object

## Resources
Bugs

* http://github.com/alaibe/big_machine/issues

Development

* http://github.com/alaibe/big_machine

Testing

* http://travis-ci.org/alaibe/big_machine

Source

* git://github.com/alaibe/big_machine.git

## Install

Add this to your Gemfile
``` ruby

  gem 'big_machine'

```

## Usage

Create your first state
``` ruby

  class Draft < BigMachine::State
    def publish
      transition_to Online
    end
  end

  class Online < BigMachine::State
  end

```

All methods you override in you state can takes args and block
``` ruby

  class Draft < BigMachine::State
    def publish(now = Time.now)
      transition_to Online, now
    end
  end

  class Online < BigMachine::State
    def enter(*args)
      stateful.publish_at args.first
    end
  end

```

Make your object stateful
``` ruby

  class Car
    include BigMachine

    big_machine initial_state: :draft
  end

```

Now it's possible to publish your car object:
``` ruby

  car = Car.new
  car.current_state # => Draft
  car.publish
  car.current_state # => Online

```

Of course your object can be an ActiveRecord::Base object. In this case, the object must have a state column. ( if not, see the next section )

## Big machine options

big_machine method can take several options:
* initial_state is the only one necessary option
* state_attribute is available only if the object is an active record object
* workflow if you want to change the normal worklow
It's possible to call workflow_is method in your different states


## Example

``` ruby

  big_machine initial_state: :dradt, state_attribute: :big_state, workflow: small

  class Draft < BigMachine::State

    def publish
      return if workflow_is :small

      transition_to Online
    end

  end

```

## Lock module

A state can include lock module, it will lock the state of your object when your enter in it.
The unlock method should be call to unlock the module

``` ruby

  class Draft < BigMachine::State
    include BigMachine::Lock

    def publish
      transition_to Online
    end

  end

  class Article
    include BigMachine

    big_machine initial_state: :dradt
  end

  article = Article.new
  article.publish
  article.current_state # => Draft
  article.unlock
  article.publish
  article.current_state # => Online

```

## Contributors

*<NAME><commit_msg>Add a Bitdeli badge to README<commit_after># Big machine [![Build Status](https://secure.travis-ci.org/alaibe/big_machine.png)][travis] [![Dependency Status](https://gemnasium.com/alaibe/big_machine.png)][gemnasium] [![Code Climate](https://codeclimate.com/badge.png)][codeclimate]

[travis]: http://travis-ci.org/alaibe/big_machine
[gemnasium]: https://gemnasium.com/alaibe/big_machine
[codeclimate]: https://codeclimate.com/github/alaibe/big_machine

Big machine is a Gem which give state to your object

## Resources
Bugs

* http://github.com/alaibe/big_machine/issues

Development

* http://github.com/alaibe/big_machine

Testing

* http://travis-ci.org/alaibe/big_machine

Source

* git://github.com/alaibe/big_machine.git

## Install

Add this to your Gemfile
``` ruby

  gem 'big_machine'

```

## Usage

Create your first state
``` ruby

  class Draft < BigMachine::State
    def publish
      transition_to Online
    end
  end

  class Online < BigMachine::State
  end

```

All methods you override in you state can takes args and block
``` ruby

  class Draft < BigMachine::State
    def publish(now = Time.now)
      transition_to Online, now
    end
  end

  class Online < BigMachine::State
    def enter(*args)
      stateful.publish_at args.first
    end
  end

```

Make your object stateful
``` ruby

  class Car
    include BigMachine

    big_machine initial_state: :draft
  end

```

Now it's possible to publish your car object:
``` ruby

  car = Car.new
  car.current_state # => Draft
  car.publish
  car.current_state # => Online

```

Of course your object can be an ActiveRecord::Base object. In this case, the object must have a state column. ( if not, see the next section )

## Big machine options

big_machine method can take several options:
* initial_state is the only one necessary option
* state_attribute is available only if the object is an active record object
* workflow if you want to change the normal worklow
It's possible to call workflow_is method in your different states


## Example

``` ruby

  big_machine initial_state: :dradt, state_attribute: :big_state, workflow: small

  class Draft < BigMachine::State

    def publish
      return if workflow_is :small

      transition_to Online
    end

  end

```

## Lock module

A state can include lock module, it will lock the state of your object when your enter in it.
The unlock method should be call to unlock the module

``` ruby

  class Draft < BigMachine::State
    include BigMachine::Lock

    def publish
      transition_to Online
    end

  end

  class Article
    include BigMachine

    big_machine initial_state: :dradt
  end

  article = Article.new
  article.publish
  article.current_state # => Draft
  article.unlock
  article.publish
  article.current_state # => Online

```

## Contributors

*<NAME>


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/alaibe/big_machine/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

{'fraction_non_alphanumeric': 0.09360889197638068, 'fraction_numerical': 0.0008683570684265369, 'mean_word_length': 3.6406124093473005, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6997026', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1750, 'n_words': 570}