README.md in solidstate-0.2.0 vs README.md in solidstate-0.3.0

- old
+ new

@@ -1,10 +1,18 @@ SolidState ========== Minuscule but solid state machine for Ruby classes. The only dependency is that your model responds to a getter and setter for `state`. +## Installation + +In your Gemfile: + + gem 'solidstate' + +## Usage + ``` ruby # simplest example, using just an accessor class Post include SolidState @@ -16,11 +24,11 @@ # in its simplest form you just declare the possible states. # if it's a simple class you just get boolean methods for checking # whether the current status is X or Y. p = Post.new - p.state # => 'draft' + p.state # => 'draft' (default value set in database) p.draft? # true p.published? # => false p.state = 'published' p.published? # => true @@ -40,10 +48,15 @@ p.state = 'published' p.valid? # => true p.state = 'deleted' p.valid? # => false + # you also get scopes for free if the class responds_to the `scope` method + + Post.published.first # => #<Post ...> + Post.draft.count # => 1 + # ok, now let's gets get fancier. we're going to declare transitions # which will govern the possible directions in which an object's state # can move to. class Subscriber < ActiveRecord::Base @@ -62,13 +75,14 @@ # since we declared transitions, we can now call #{state}! which # checks whether the instance can transition to that state and # if so, sets the new state and optionally saves the record. s.active! # => true - + s.state # => 'active' s.inactive! # => raises InvalidTransitionError # this also works outside transition methods, of course. + s.reload # => true s.active? # => true s.state = 'inactive' s.valid? # => false