celluloid-fsm 0.9.0.pre10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95bf4a47e617d073a6f9a4ccddaa820da5cff216
4
+ data.tar.gz: 4e3ab9b7568ae69898d19b82d0723b3ade820989
5
+ SHA512:
6
+ metadata.gz: a1cc6f16e95919b1949066b09abb115aee4de991b5faecb2969a57a43cdae36690c3143470e1d8fc1cd4db2d9a62f7f4285a1e6e32eb4eb1a126ff1bc2265712
7
+ data.tar.gz: 42c0a75d46875962b645c05108768a45a0e41a0d4bcb791fc887ad826809cce473290972ccfe1216d785823808a22b61edb5af0dceeb23d132a3a7769f649bc3
data/.env-ci ADDED
@@ -0,0 +1,4 @@
1
+ CELLULOID_SPECS_LOG_STRATEGY=stderr
2
+ CELLULOID_SPECS_LOG_LEVEL=3
3
+ CELLULOID_SPECS_LOG_FILE=../../log/ci.log
4
+ CELLULOID_SPECS_LOG_SYNC=false
data/.env-dev ADDED
@@ -0,0 +1,4 @@
1
+ CELLULOID_SPECS_LOG_STRATEGY=single
2
+ CELLULOID_SPECS_LOG_FILE=../../log/test.log
3
+ CELLULOID_SPECS_LOG_LEVEL=0
4
+ CELLULOID_SPECS_LOG_SYNC=true
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ coverage/
2
+ rdoc/
3
+ doc/
4
+ pkg/
5
+ tmp/
6
+ .yardoc
7
+ .bundle
8
+ Gemfile.lock
9
+ log
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "culture"]
2
+ path = culture
3
+ url = http://github.com/celluloid/culture.git
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format documentation
3
+ --order random
4
+ --warnings
5
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - culture/rubocop/rubocop.yml
data/.travis.yml ADDED
@@ -0,0 +1,34 @@
1
+ script: rake ci
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ - 2.2.2
6
+ - jruby
7
+ - ruby-head
8
+ - jruby-head
9
+ - rbx-2
10
+
11
+ # TODO: Put these back:
12
+ # * CELLULOID_TASK_CLASS=Fibered
13
+ # * CELLULOID_TASK_CLASS=Threaded
14
+ # For right now the imporant thing is to test BACKPORTED mode:
15
+
16
+ matrix:
17
+ allow_failures:
18
+ - rvm: rbx-2
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ - env: CELLULOID_BACKPORTED=true
22
+
23
+ env:
24
+ matrix:
25
+ - CELLULOID_BACKPORTED=true
26
+ - CELLULOID_BACKPORTED=false
27
+ global:
28
+ - NUMBER_OF_PROCESSORS=2 CELLULOID_CONFIG_FILE=.env-ci
29
+
30
+ notifications:
31
+ irc: "irc.freenode.org#celluloid"
32
+
33
+ sudo: false
34
+ install: bundle install --retry=3 --without=development
data/CHANGES.md ADDED
@@ -0,0 +1,4 @@
1
+ 0.8.5 (2015-04-11)
2
+ -----
3
+
4
+ * Initial release of separated gem, extracted from Celluloid.
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ require File.expand_path("../culture/sync", __FILE__)
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec development_group: :gem_build_tools
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ # gem 'guard'
9
+ # gem 'guard-rspec'
10
+ # gem 'rb-fsevent', '~> 0.9.1' if RUBY_PLATFORM =~ /darwin/
11
+ end
12
+
13
+ group :test do
14
+ gem 'dotenv', '~> 2.0'
15
+ gem 'nenv'
16
+ gem 'benchmark_suite'
17
+ gem 'rspec', '~> 3.2'
18
+ end
19
+
20
+ group :gem_build_tools do
21
+ gem 'rake'
22
+ end
23
+
24
+ Celluloid::Sync.gems(self)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Celluloid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # Celluloid::FSM
2
+ ---
3
+
4
+ * Prerelease gem.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ Dir['tasks/**/*.rake'].each { |task| load task }
4
+
5
+ default_tasks = ['spec']
6
+ default_tasks << 'rubocop' unless ENV['CI']
7
+ task default: default_tasks
8
+
9
+ task ci: %w(spec benchmark)
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../culture/sync", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'celluloid-fsm'
6
+ gem.version = '0.9.0.pre10'
7
+ gem.platform = Gem::Platform::RUBY
8
+ gem.summary = 'Celluloid Finite State Machines'
9
+ gem.description = 'Simple finite state machines with integrated Celluloid timeout support.'
10
+ gem.licenses = ['MIT']
11
+
12
+ gem.authors = ["Tony Arcieri", "Tim Carey-Smith", "digitalextremist //"]
13
+ gem.email = ['tony.arcieri@gmail.com', 'code@extremist.digital']
14
+ gem.homepage = 'https://github.com/celluloid/celluloid-fsm'
15
+
16
+ gem.required_ruby_version = '>= 1.9.2'
17
+ gem.required_rubygems_version = '>= 1.3.6'
18
+
19
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|examples|spec|features)/}) }
20
+ gem.require_path = 'lib'
21
+
22
+ Celluloid::Sync.gems(gem)
23
+ end
@@ -0,0 +1,187 @@
1
+ require 'celluloid' unless defined? Celluloid
2
+
3
+ module Celluloid
4
+ # Simple finite state machines with integrated Celluloid timeout support
5
+ # Inspired by Erlang's gen_fsm (http://www.erlang.org/doc/man/gen_fsm.html)
6
+ #
7
+ # Basic usage:
8
+ #
9
+ # class MyMachine
10
+ # include Celluloid::FSM # NOTE: this does NOT pull in the Celluloid module
11
+ # end
12
+ #
13
+ # Inside an actor:
14
+ #
15
+ # #
16
+ # machine = MyMachine.new(current_actor)
17
+ module FSM
18
+ class UnattachedError < Celluloid::Error; end # Not attached to an actor
19
+
20
+ DEFAULT_STATE = :default # Default state name unless one is explicitly set
21
+
22
+ # Included hook to extend class methods
23
+ def self.included(klass)
24
+ klass.send :extend, ClassMethods
25
+ end
26
+
27
+ module ClassMethods
28
+ # Obtain or set the default state
29
+ # Passing a state name sets the default state
30
+ def default_state(new_default = nil)
31
+ if new_default
32
+ @default_state = new_default.to_sym
33
+ else
34
+ defined?(@default_state) ? @default_state : DEFAULT_STATE
35
+ end
36
+ end
37
+
38
+ # Obtain the valid states for this FSM
39
+ def states
40
+ @states ||= {}
41
+ end
42
+
43
+ # Declare an FSM state and optionally provide a callback block to fire
44
+ # Options:
45
+ # * to: a state or array of states this state can transition to
46
+ def state(*args, &block)
47
+ if args.last.is_a? Hash
48
+ # Stringify keys :/
49
+ options = args.pop.each_with_object({}) { |(k,v), h| h[k.to_s] = v }
50
+ else
51
+ options = {}
52
+ end
53
+
54
+ args.each do |name|
55
+ name = name.to_sym
56
+ default_state name if options['default']
57
+ states[name] = State.new(name, options['to'], &block)
58
+ end
59
+ end
60
+ end
61
+
62
+ attr_reader :actor
63
+
64
+ # Be kind and call super if you must redefine initialize
65
+ def initialize(actor = nil)
66
+ @state = self.class.default_state
67
+ @delayed_transition = nil
68
+ @actor = actor
69
+ @actor ||= Celluloid.current_actor if Celluloid.actor?
70
+ end
71
+
72
+ # Obtain the current state of the FSM
73
+ attr_reader :state
74
+
75
+ # Attach this FSM to an actor. This allows FSMs to wait for and initiate
76
+ # events in the context of a particular actor
77
+ def attach(actor)
78
+ @actor = actor
79
+ end
80
+ alias_method :actor=, :attach
81
+
82
+ # Transition to another state
83
+ # Options:
84
+ # * delay: don't transition immediately, wait the given number of seconds.
85
+ # This will return a Celluloid::Timer object you can use to
86
+ # cancel the pending state transition.
87
+ #
88
+ # Note: making additional state transitions will cancel delayed transitions
89
+ def transition(state_name, options = {})
90
+ new_state = validate_and_sanitize_new_state(state_name)
91
+ return unless new_state
92
+
93
+ if handle_delayed_transitions(new_state, options[:delay])
94
+ return @delayed_transition
95
+ end
96
+
97
+ transition_with_callbacks!(new_state)
98
+ end
99
+
100
+ # Immediate state transition with no sanity checks, or callbacks. "Dangerous!"
101
+ def transition!(state_name)
102
+ @state = state_name
103
+ end
104
+
105
+ protected
106
+
107
+ def validate_and_sanitize_new_state(state_name)
108
+ state_name = state_name.to_sym
109
+
110
+ return if current_state_name == state_name
111
+
112
+ if current_state and not current_state.valid_transition? state_name
113
+ valid = current_state.transitions.map(&:to_s).join(", ")
114
+ raise ArgumentError, "#{self.class} can't change state from '#{@state}' to '#{state_name}', only to: #{valid}"
115
+ end
116
+
117
+ new_state = states[state_name]
118
+
119
+ unless new_state
120
+ return if state_name == default_state
121
+ raise ArgumentError, "invalid state for #{self.class}: #{state_name}"
122
+ end
123
+
124
+ new_state
125
+ end
126
+
127
+ def transition_with_callbacks!(state_name)
128
+ transition! state_name.name
129
+ state_name.call(self)
130
+ end
131
+
132
+ def states
133
+ self.class.states
134
+ end
135
+
136
+ def default_state
137
+ self.class.default_state
138
+ end
139
+
140
+ def current_state
141
+ states[@state]
142
+ end
143
+
144
+ def current_state_name
145
+ current_state && current_state.name || ''
146
+ end
147
+
148
+ def handle_delayed_transitions(new_state, delay)
149
+ if delay
150
+ raise UnattachedError, "can't delay unless attached" unless @actor
151
+ @delayed_transition.cancel if @delayed_transition
152
+
153
+ @delayed_transition = @actor.after(delay) do
154
+ transition_with_callbacks!(new_state)
155
+ end
156
+
157
+ return @delayed_transition
158
+ end
159
+
160
+ return unless defined?(@delayed_transition) and @delayed_transition
161
+ @delayed_transition.cancel
162
+ @delayed_transition = nil
163
+ end
164
+
165
+ # FSM states as declared by Celluloid::FSM.state
166
+ class State
167
+ attr_reader :name, :transitions
168
+
169
+ def initialize(name, transitions = nil, &block)
170
+ @name, @block = name, block
171
+ @transitions = nil
172
+ @transitions = Array(transitions).map(&:to_sym) if transitions
173
+ end
174
+
175
+ def call(obj)
176
+ obj.instance_eval(&@block) if @block
177
+ end
178
+
179
+ def valid_transition?(new_state)
180
+ # All transitions are allowed unless expressly
181
+ return true unless @transitions
182
+
183
+ @transitions.include? new_state.to_sym
184
+ end
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,16 @@
1
+ require 'timeout'
2
+
3
+ desc "Run Celluloid benchmarks"
4
+ task :benchmark do
5
+ begin
6
+ Timeout.timeout(120) do
7
+ glob = File.expand_path("../../benchmarks/*.rb", __FILE__)
8
+ Dir[glob].each { |benchmark| load benchmark }
9
+ end
10
+ rescue Exception, Timeout::Error => ex
11
+ puts "ERROR: Couldn't complete benchmark: #{ex.class}: #{ex}"
12
+ puts " #{ex.backtrace.join("\n ")}"
13
+
14
+ exit 1 unless ENV['CI'] # Hax for running benchmarks on Travis
15
+ end
16
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
@@ -0,0 +1,4 @@
1
+ unless ENV['CI']
2
+ require 'rubocop/rake_task'
3
+ RuboCop::RakeTask.new
4
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: celluloid-fsm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0.pre10
5
+ platform: ruby
6
+ authors:
7
+ - Tony Arcieri
8
+ - Tim Carey-Smith
9
+ - digitalextremist //
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-04-30 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ name: bundler
22
+ prerelease: false
23
+ type: :development
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ name: coveralls
36
+ prerelease: false
37
+ type: :development
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ name: celluloid
50
+ prerelease: false
51
+ type: :development
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ name: celluloid-essentials
64
+ prerelease: false
65
+ type: :development
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ name: celluloid-supervision
78
+ prerelease: false
79
+ type: :development
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ name: celluloid-pool
92
+ prerelease: false
93
+ type: :development
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ name: celluloid-extras
106
+ prerelease: false
107
+ type: :development
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ name: timers
120
+ prerelease: false
121
+ type: :development
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ name: rubocop
134
+ prerelease: false
135
+ type: :development
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ name: rspec-log_split
148
+ prerelease: false
149
+ type: :development
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ description: Simple finite state machines with integrated Celluloid timeout support.
156
+ email:
157
+ - tony.arcieri@gmail.com
158
+ - code@extremist.digital
159
+ executables: []
160
+ extensions: []
161
+ extra_rdoc_files: []
162
+ files:
163
+ - .env-ci
164
+ - .env-dev
165
+ - .gitignore
166
+ - .gitmodules
167
+ - .rspec
168
+ - .rubocop.yml
169
+ - .travis.yml
170
+ - CHANGES.md
171
+ - Gemfile
172
+ - LICENSE.txt
173
+ - README.md
174
+ - Rakefile
175
+ - celluloid-fsm.gemspec
176
+ - lib/celluloid/fsm.rb
177
+ - tasks/benchmarks.rake
178
+ - tasks/rspec.rake
179
+ - tasks/rubocop.rake
180
+ homepage: https://github.com/celluloid/celluloid-fsm
181
+ licenses:
182
+ - MIT
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - '>='
191
+ - !ruby/object:Gem::Version
192
+ version: 1.9.2
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '>='
196
+ - !ruby/object:Gem::Version
197
+ version: 1.3.6
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.4.6
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: Celluloid Finite State Machines
204
+ test_files: []