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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40cb0d3afb2f9c64b8eb616492132d2c45d424f0
4
- data.tar.gz: 7ccefb4f23c017273a13c5b696bdbf10b2978db6
3
+ metadata.gz: 8d562b809eb29d6a33b1768b0561f58a45bb22c1
4
+ data.tar.gz: 174a24056758854ca81477e763fa6f221b09dcb4
5
5
  SHA512:
6
- metadata.gz: 1c95e4e56f4c9da12c9bf07cf007060e885f7201b646ea0c5d604a949d51f27b8684ac7f202bcdaf9507afa808f17b6264e6e45d1db524089a24a43a44e28e05
7
- data.tar.gz: 26e7aeba3f817d853f9f6bce6a4695f6a76a0f00c728b4b1a8a7d2e3f3d3932f6f3cc7254ae43afea8a0c5b60eeebc1a4ffe8f53fdf382208aa19b9b3ecf096f
6
+ metadata.gz: f1b7420c9020b34027472def39c30bf11c34a3cc63d5c9c925d6237b3d57f09c89dad9329438d06b8ebd84b20e3c0a130dd938697992b4da693b34f12a153c80
7
+ data.tar.gz: 3a651a37be0fe7fd52e7c6b399a85dbb6651389c9d7076e0a8e047f0cd4b9c0eaaf151eb56be62085092b8daccb932910fcf53ed5686d1706bba8bbba5d6d3ef
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.5
4
+ - 2.2.0
5
+ cache: bundler
6
+ sudo: false
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 = '1.0.0'
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
- @mutex.synchronize do
151
- dispatch_callbacks_before_transition(new_state)
152
- previous = @state
153
- @state = new_state.to_sym
154
- @flow << new_state.to_sym
155
- dispatch_callbacks_after_transition(previous)
156
- previous
157
- end
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 1.0.0 ruby lib
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 = "1.0.0"
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-01-14"
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: 1.0.0
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-01-14 00:00:00.000000000 Z
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