https://github.com/siman-man/state_transition
StateMachine for Ruby
https://github.com/siman-man/state_transition
gem ruby
Last synced: 11 months ago
JSON representation
StateMachine for Ruby
- Host: GitHub
- URL: https://github.com/siman-man/state_transition
- Owner: siman-man
- License: mit
- Created: 2013-08-19T04:16:00.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-04-27T15:29:38.000Z (about 12 years ago)
- Last Synced: 2025-07-28T17:13:25.860Z (12 months ago)
- Topics: gem, ruby
- Language: Ruby
- Size: 223 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# StateTransition
https://github.com/jakesgordon/javascript-state-machine
This program is very useful. so I created ruby ver.
version 0.1.0 is active only upper 2.1.0.
## Installation
Add this line to your application's Gemfile:
gem 'state_transition'
And then execute:
$ bundle
Or install it yourself as:
$ gem install state_transition
## Usage
require 'state_transition'
state = StateTransition::StateMachine.new({
initial: :first,
actions: [
{ name: "move_first", from: [ :second, :third ], to: :first },
{ name: "move_second", from: [ :first, :third ], to: :second },
{ name: "move_third", from: :second, to: :third },
],
callbacks: {
before_second: -> { puts "before_second" },
after_second: -> { puts "after_second" },
}
})
puts state.current #=> :first
puts state.can_move?(:second) #=> true
puts state.can_move?(:third) #=> false
state.move_second
puts state.current #=> :second
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request