Last active
August 29, 2015 14:10
-
-
Save dougfarre/690965f8b6bb12424a8a to your computer and use it in GitHub Desktop.
Business/Model Logic Inside State Machine?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OrderStateMachine | |
| include Statesman::Machine | |
| # Possible states | |
| state :entered, initial: true | |
| state :validating | |
| state :validated | |
| state :invalidated | |
| # Allowed transitions | |
| transition from: :entered, to: [:validating] | |
| transition from: :validating, to: [:validated, :invalidated] | |
| # Events | |
| event :validate do |model| | |
| transition from: :entered, to: :validating | |
| if model.valid? | |
| transition from: :validating, to: :validated | |
| else | |
| transition from: :validation, to: :invalidated | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment