very_tiny_state_machine 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +3 -1
- data/lib/very_tiny_state_machine.rb +9 -11
- data/very_tiny_state_machine.gemspec +4 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d562b809eb29d6a33b1768b0561f58a45bb22c1
|
4
|
+
data.tar.gz: 174a24056758854ca81477e763fa6f221b09dcb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1b7420c9020b34027472def39c30bf11c34a3cc63d5c9c925d6237b3d57f09c89dad9329438d06b8ebd84b20e3c0a130dd938697992b4da693b34f12a153c80
|
7
|
+
data.tar.gz: 3a651a37be0fe7fd52e7c6b399a85dbb6651389c9d7076e0a8e047f0cd4b9c0eaaf151eb56be62085092b8daccb932910fcf53ed5686d1706bba8bbba5d6d3ef
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# very_tiny_state_machine
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/WeTransfer/very_tiny_state_machine.svg?branch=master)](https://travis-ci.org/WeTransfer/very_tiny_state_machine)
|
4
|
+
|
3
5
|
For when the others are not tiny enough.
|
4
6
|
|
5
7
|
The entire state machine lives in a separate variable, and does not pollute the class or the module of the caller.
|
@@ -12,7 +14,7 @@ are dispatched to the given object as messages.
|
|
12
14
|
@automaton.permit_transition :closing => :closed
|
13
15
|
|
14
16
|
# Then, lower down the code
|
15
|
-
@automaton.transition! :processing
|
17
|
+
@automaton.transition! :processing
|
16
18
|
|
17
19
|
The object supplied as the optional second argument will receive messages when states are switched around,
|
18
20
|
in the following order (using the state machine from the previous example):
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'thread'
|
2
1
|
require 'set'
|
3
2
|
|
4
3
|
# A mini state machine object that can be used to track a state flow.
|
@@ -33,7 +32,7 @@ require 'set'
|
|
33
32
|
# @automaton.in_state?(:processing) #=> true
|
34
33
|
# @automaton.in_state?(:initialized) #=> false
|
35
34
|
class VeryTinyStateMachine
|
36
|
-
VERSION = '
|
35
|
+
VERSION = '2.0.0'
|
37
36
|
|
38
37
|
InvalidFlow = Class.new(StandardError) # Gets raised when an impossible transition gets requested
|
39
38
|
UnknownState = Class.new(StandardError) # Gets raised when an unknown state gets requested
|
@@ -43,7 +42,6 @@ class VeryTinyStateMachine
|
|
43
42
|
# @param initial_state[#to_sym] the initial state of the state machine
|
44
43
|
# @param object_handling_callbacks[#send, #respond_to?] the callback handler that will receive transition notifications
|
45
44
|
def initialize(initial_state, object_handling_callbacks = nil)
|
46
|
-
@mutex = Mutex.new
|
47
45
|
@state = initial_state.to_sym
|
48
46
|
@flow = [@state]
|
49
47
|
@permitted_states = Set.new([initial_state])
|
@@ -147,14 +145,14 @@ class VeryTinyStateMachine
|
|
147
145
|
|
148
146
|
raise UnknownState, new_state.inspect unless known?(new_state)
|
149
147
|
if may_transition_to?(new_state)
|
150
|
-
@
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
148
|
+
dispatch_callbacks_before_transition(new_state) if @callbacks_via
|
149
|
+
|
150
|
+
previous = @state
|
151
|
+
@state = new_state.to_sym
|
152
|
+
@flow << new_state.to_sym
|
153
|
+
|
154
|
+
dispatch_callbacks_after_transition(previous) if @callbacks_via
|
155
|
+
previous
|
158
156
|
else
|
159
157
|
raise InvalidFlow,
|
160
158
|
"Cannot change states from #{@state} to #{new_state} (flow so far: #{@flow.join(' > ')})"
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: very_tiny_state_machine
|
5
|
+
# stub: very_tiny_state_machine 2.0.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "very_tiny_state_machine"
|
9
|
-
s.version = "
|
9
|
+
s.version = "2.0.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Julik Tarkhanov"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-02-04"
|
15
15
|
s.description = "You wouldn't beleive how tiny it is"
|
16
16
|
s.email = "me@julik.nl"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".rspec",
|
24
|
+
".travis.yml",
|
24
25
|
"Gemfile",
|
25
26
|
"LICENSE.txt",
|
26
27
|
"README.md",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: very_tiny_state_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -90,6 +90,7 @@ extra_rdoc_files:
|
|
90
90
|
files:
|
91
91
|
- ".document"
|
92
92
|
- ".rspec"
|
93
|
+
- ".travis.yml"
|
93
94
|
- Gemfile
|
94
95
|
- LICENSE.txt
|
95
96
|
- README.md
|