No commit activity in last 3 years
No release in over 3 years
Adapter to allow Mongoid to persist and restore state of objects using the AlterEgo state machine, ported from the alter-ego-activerecord gem by Paul Hieromnimon
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.0.1
~> 1.2
>= 2.0.0.rc.6
 Project Readme

AlterEgo-Mongoid¶ ↑

Motivation¶ ↑

AlterEgo is my favorite Ruby state machine for the following reasons:

1. It's not dependent on Mongoid - it can be used on plain Ruby objects.
2. It most closely follows the GOF State Pattern because it allows for 
   polymorphic behavior based on state.

Out of the box, AlterEgo doesn’t play nicely with Mongoid because it stores state in @state, whereas Mongoid::Document persists with setter methods.

This mixin overrides the AlterEgo’s accessor methods for state to allow it to be properly persisted to a database, as well as serialized/unserialized as json, yml, and xml.

Installation¶ ↑

As a Ruby Gem ¶ ↑

gem install alter-ego
gem install alter-ego-mongoid

OR using Rails 3 Bundle¶ ↑

gem 'alter-ego', :require => 'alter_ego'
gem 'alter-ego-mongoid', :require => 'alter_ego/mongoid_adapter'

OR as a Rails plugin¶ ↑

script/plugin install git://github.com/wink/alter-ego-mongoid.git

Usage¶ ↑

This plugin automatically adds a string field to your model called “state”.

# you'll only need the following two lines if you're NOT using
# alter-ego-mongoid as a plugin
gem 'alter-ego-mongoid'
require 'alter_ego/mongoid_adapter'

class Example
  include Mongoid::Document
  include AlterEgo # include this first
  include AlterEgo::MongoidAdapter

  # Your code here
end