TransitionValidator

A custom validator for stateful attribute transitions. It's use perfect with state_validator for the State Machine implementation in your application.

Installation

Add this line to your application's Gemfile:

gem 'transition_validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install transition_validator

Usage

Place validator into your model:

validates :my_state_attribute, :transition => true

Place list of transitions:

def my_state_attribute_transitions
  {
    nil => ['on' , 'off'],
    'on' => ['off'],
    'off' => ['on']
  }
end

Place required methods to do transition actions:

def off_to_on_my_state_attribute_transition
  # Place actions for change a state of attribute "my_state_attribute" from "off" to "on"
end

def _to_on_my_state_attribute_transition
  # Place actions for change a state of attribute "my_state_attribute" from nil to "on"
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request