README.md in state_objects-0.0.2 vs README.md in state_objects-0.0.3

- old
+ new

@@ -6,10 +6,15 @@ You can add methods to the state classes, but each state class must have implement the same list of methods. State transitions are the responsibility of the state classes. Since this was extracted from an application, the specs are currently still in the main application. I will move the specs to this gem as soon as possible. +## Focus +Many state machines focus on events and state transitions. +The main benefit of this gem is to reduce conditional logic by removing #if checks in the model and moving the logic into the state objects. Using Composition in this way can go a long way to simplify Rails models. + + ## Installation Add this line to your application's Gemfile: gem 'state_objects' @@ -50,11 +55,11 @@ class WalkLight < ActiveRecord::Base extend StateObjects::ModelAdditions state_objects :color_state, LightGreenState, LightRedState - state_object_events :change + state_object_events :color_state, :change scope :red, where("color_state = #{LightRedState.db_value}" ) scope :green, where("color_state = #{LightGreenState.db_value}" ) end @@ -74,18 +79,15 @@ The second example shows how to start the selection on a blank <%= select :walk_light, :color_state, WalkLight.color_states %> <%= select :walk_light, :color_state, [['','']] + WalkLight.color_states %> - assert_equal ['Walk', 'Dont Walk'], WalkLight.color_state_hash.values assert_equal "['Walk', 'Dont Walk']", WalkLight.color_state_js_list - color_state_symbols # returns hash of symbols adds the following INSTANCE METHODS to WalkLight - color_state_hash color_state # returns the single character value as in the db color_state_label # returns the current values label color_state_symbol # returns the current values symbol * methods ending in '?' return boolean if the value is set @@ -105,11 +107,9 @@ assert_equal :red, walk_light.color_state_symbol assert_equal true, walk_light.color_state_red? assert_equal "Dont Walk", walk_light.color_state_label assert_equal [["Walk", "G"], ["Dont Walk", "R"]], WalkLight.color_states - assert_equal({"G"=>"Walk", "R"=>"Dont Walk",}, WalkLight.color_state_hash) - assert_equals({'G'=>:green, 'R'=>:red }, WalkLight.color_state_symbols) ### Example #2: Selection list <%= select :walk_light, :color_state, WalkLight.color_states %>