RubyGems Navigation menu

nanomachine 1.0.0

A really tiny state machine for ruby. No events, only accepted transitions and transition callbacks. The difference between Nanomachine, and otherwise known Micromachine (https://rubygems.org/gems/micromachine) is that Micromachine transitions to new states in response to events; multiple events can transition between the two same states. Nanomachine, on the other hand, does not care about events, and only needs the state you want to be in after successful transition. Nanomachine can be used in any ruby project, and have no runtime dependencies. Example: state_machine = Nanomachine.new("unpublished") do |fsm| fsm.transition("published", %w[unpublished processing removed]) fsm.transition("unpublished", %w[published processing removed]) fsm.transition("processing", %w[published unpublished]) fsm.transition("removed", []) # defined for being explicit fsm.on_transition do |(from_state, to_state)| update_column(:state, to_state) end end if state_machine.transition_to("published") puts "Publish success!" else puts "Publish failure! We’re in #{state_machine.state}." end

Gemfile:
= Copy to clipboard Copied!

install:
=

Versions:

  1. 1.1.0 - October 28, 2015 (10 KB)
  2. 1.0.1 - November 15, 2012 (8.5 KB)
  3. 1.0.0 - November 15, 2012 (9 KB)

Development Dependencies (2):

rake >= 0
rspec ~> 2.0

Owners:

Authors:

  • Ivan Navarrete, Kim Burgestrand

SHA 256 checksum:

0837465458d2cd1c0433d487e6673be94645429ada99fca938888b16ab7cebab

Total downloads 9,951

For this version 2,919

Licenses:

N/A

Required Ruby Version: None

Links: