ruby-state-machine 1.0.2 → 1.1.0
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.
- data/README.md +87 -0
- data/lib/ruby-state-machine.rb +3 -3
- data/lib/ruby-state-machine/state_machine.rb +6 -3
- data/lib/ruby-state-machine/version.rb +8 -0
- metadata +38 -99
- data/History.txt +0 -32
- data/Manifest.txt +0 -20
- data/PostInstall.txt +0 -1
- data/README.rdoc +0 -48
- data/Rakefile +0 -26
- data/config/website.yml +0 -2
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -71
- data/test/test_helper.rb +0 -3
- data/test/test_state_machine.rb +0 -212
- data/website/index.html +0 -104
- data/website/index.txt +0 -55
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -159
- data/website/template.html.erb +0 -50
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
## Ruby State Machine
|
2
|
+
Ruby State Machine (ruby-state-machine) is a full-featured state machine gem for use within ruby. It can also be used in Rails. This was written because we required a state machine that allowed different actions to be performed based on the previous and current events, as well as injecting logic (a "decider") to determine the next event.
|
3
|
+
|
4
|
+
## Installation:
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
gem 'ruby-state-machine'
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
|
12
|
+
$ bundle
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
|
16
|
+
$ gem install ruby-state-machine
|
17
|
+
|
18
|
+
## Location:
|
19
|
+
Here: http://github.com/tangledpath/ruby-state-machine
|
20
|
+
|
21
|
+
RDocs: http://ruby-state-mach.rubyforge.org/
|
22
|
+
|
23
|
+
|
24
|
+
## USAGE:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'ruby-state-machine/state_machine'
|
28
|
+
|
29
|
+
# Note, a state machine is not created directly; instead, the behavior of a state
|
30
|
+
# machine is added through a mixin, e.g.:
|
31
|
+
class SampleMachine
|
32
|
+
include StateMachine
|
33
|
+
state_machine :states => [:a_state, :b_state, :c_state, :d_state], :events => [:w_event, :x_event, :y_event, :z_event]
|
34
|
+
state_transition :state=>:a_state, :event=>:x_event, :next=>:c_state # Define next state for :a_state when :x_event is sent
|
35
|
+
state_transition :state=>:a_state, :event=>:y_event, :next=>:a_state # Define next state for :a_state when :y_event is sent
|
36
|
+
state_transition :state=>:a_state, :event=>:z_event, :next=>:b_state # ...
|
37
|
+
|
38
|
+
state_transition :state=>:b_state, :event=>:w_event, :next=>:b_state
|
39
|
+
state_transition :state=>:b_state, :event=>:y_event, :next=>:c_state
|
40
|
+
state_transition :state=>:b_state, :event=>:z_event, :next=>:a_state
|
41
|
+
|
42
|
+
state_transition :state=>:c_state, :event=>:x_event, :next=>:b_state
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
sm = SampleMachine.new
|
47
|
+
puts sm.current_state # :a_state
|
48
|
+
sm.send_event(:x_event)
|
49
|
+
puts sm.current_state # :c_state
|
50
|
+
```
|
51
|
+
|
52
|
+
For examples of other functionality, including branching, deciders, lambdas, etc, see http://ruby-state-mach.rubyforge.org/StateMachine/ClassMethods.html#state_transition-instance_method.
|
53
|
+
|
54
|
+
|
55
|
+
## CONTRIBUTE
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
62
|
+
|
63
|
+
## LICENSE:
|
64
|
+
|
65
|
+
(The MIT License)
|
66
|
+
|
67
|
+
Copyright (c) 2007-2013 Steven Miers
|
68
|
+
|
69
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
70
|
+
a copy of this software and associated documentation files (the
|
71
|
+
'Software'), to deal in the Software without restriction, including
|
72
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
73
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
74
|
+
permit persons to whom the Software is furnished to do so, subject to
|
75
|
+
the following conditions:
|
76
|
+
|
77
|
+
The above copyright notice and this permission notice shall be
|
78
|
+
included in all copies or substantial portions of the Software.
|
79
|
+
|
80
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
81
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
82
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
83
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
84
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
85
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
86
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
87
|
+
|
data/lib/ruby-state-machine.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "ruby-state-machine/version"
|
2
|
+
#require "ruby-state-machine/state_machine"
|
3
3
|
|
4
4
|
module RubyStateMachine
|
5
|
-
|
5
|
+
|
6
6
|
end
|
@@ -5,9 +5,12 @@ require 'ruby-state-machine/bounded_array'
|
|
5
5
|
# an array of events, and one or more transition actions. A transition can be
|
6
6
|
# as simple as the symbol for the next state, a lambda (code) to execute. Primitive
|
7
7
|
# branching can also be achieved if necessary by using a "decider" instance method.
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# of the available functionality.
|
8
|
+
#
|
9
|
+
# The {StateMachineTest} (view source) also contains examples and unit tests for most (if not all)
|
10
|
+
# of the available functionality.
|
11
|
+
# Also see {http://ruby-state-mach.rubyforge.org/ README} for examples
|
12
|
+
# @see ClassMethods#state_transition StateTransition for full details on the variations available.
|
13
|
+
# @see StateMachineTest
|
11
14
|
module StateMachine
|
12
15
|
def self.included(base)
|
13
16
|
base.extend StateMachine::ClassMethods
|
metadata
CHANGED
@@ -1,114 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-state-machine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 1.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
7
|
+
authors:
|
8
|
+
- tangledpath
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: rubyforge
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 2
|
29
|
-
- 0
|
30
|
-
- 4
|
31
|
-
version: 2.0.4
|
32
|
-
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: hoe
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 2
|
43
|
-
- 6
|
44
|
-
- 0
|
45
|
-
version: 2.6.0
|
46
|
-
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
description: FIX (describe your package)
|
49
|
-
email:
|
12
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A ruby state machine
|
15
|
+
email:
|
50
16
|
- steven.miers@gmail.com
|
51
17
|
executables: []
|
52
|
-
|
53
18
|
extensions: []
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
- Manifest.txt
|
58
|
-
- PostInstall.txt
|
59
|
-
- website/index.txt
|
60
|
-
files:
|
61
|
-
- History.txt
|
62
|
-
- Manifest.txt
|
63
|
-
- PostInstall.txt
|
64
|
-
- README.rdoc
|
65
|
-
- Rakefile
|
66
|
-
- config/website.yml
|
67
|
-
- lib/ruby-state-machine.rb
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
files:
|
68
22
|
- lib/ruby-state-machine/bounded_array.rb
|
69
23
|
- lib/ruby-state-machine/state_machine.rb
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
|
74
|
-
- test/test_helper.rb
|
75
|
-
- test/test_state_machine.rb
|
76
|
-
- website/index.html
|
77
|
-
- website/index.txt
|
78
|
-
- website/javascripts/rounded_corners_lite.inc.js
|
79
|
-
- website/stylesheets/screen.css
|
80
|
-
- website/template.html.erb
|
81
|
-
has_rdoc: true
|
82
|
-
homepage: http://github.com/#{github_username}/#{project_name}
|
24
|
+
- lib/ruby-state-machine/version.rb
|
25
|
+
- lib/ruby-state-machine.rb
|
26
|
+
- README.md
|
27
|
+
homepage: http://github.com/tangledpath/ruby-state-machine
|
83
28
|
licenses: []
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
- --main
|
88
|
-
- README.rdoc
|
89
|
-
require_paths:
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
90
32
|
- lib
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
version:
|
98
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
version: "0"
|
33
|
+
- ext
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
105
46
|
requirements: []
|
106
|
-
|
107
|
-
|
108
|
-
rubygems_version: 1.3.6
|
47
|
+
rubyforge_project: ruby-state-machine
|
48
|
+
rubygems_version: 1.8.25
|
109
49
|
signing_key:
|
110
50
|
specification_version: 3
|
111
|
-
summary:
|
112
|
-
test_files:
|
113
|
-
|
114
|
-
- test/test_state_machine.rb
|
51
|
+
summary: A full-featured state machine gem for use within ruby.
|
52
|
+
test_files: []
|
53
|
+
has_rdoc: true
|
data/History.txt
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
== 0.0.1 2009-08-11
|
2
|
-
|
3
|
-
* 1 major enhancement:
|
4
|
-
* Initial release
|
5
|
-
|
6
|
-
== 0.0.2 2009-08-11
|
7
|
-
|
8
|
-
* 1 minor enhancement:
|
9
|
-
* Docs
|
10
|
-
|
11
|
-
== 0.0.3 2009-08-17
|
12
|
-
|
13
|
-
* 1 minor enhancement:
|
14
|
-
* Change ruby-state-mach -> ruby-state-machine
|
15
|
-
|
16
|
-
== 0.0.4 2009-08-19
|
17
|
-
|
18
|
-
* 1 minor enhancement:
|
19
|
-
* Add missing files
|
20
|
-
|
21
|
-
== 1.0.1 2010-05-03
|
22
|
-
|
23
|
-
* 1 bug fix:
|
24
|
-
* Fix initialize to call super when used on AR models.
|
25
|
-
|
26
|
-
== 1.0.2 2010-05-18
|
27
|
-
|
28
|
-
* 1 behavioral change:
|
29
|
-
* No longer returns to default state upon InvalidStateException. This was making several unit tests more difficult than necessary.
|
30
|
-
|
31
|
-
|
32
|
-
|
data/Manifest.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
PostInstall.txt
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
|
-
config/website.yml
|
7
|
-
lib/ruby-state-machine.rb
|
8
|
-
lib/ruby-state-machine/bounded_array.rb
|
9
|
-
lib/ruby-state-machine/state_machine.rb
|
10
|
-
script/console
|
11
|
-
script/destroy
|
12
|
-
script/generate
|
13
|
-
script/txt2html
|
14
|
-
test/test_helper.rb
|
15
|
-
test/test_state_machine.rb
|
16
|
-
website/index.html
|
17
|
-
website/index.txt
|
18
|
-
website/javascripts/rounded_corners_lite.inc.js
|
19
|
-
website/stylesheets/screen.css
|
20
|
-
website/template.html.erb
|
data/PostInstall.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
For more information on ruby-state-machine, see http://ruby-state-mach.rubyforge.org
|
data/README.rdoc
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
= ruby-state-machine
|
2
|
-
|
3
|
-
* http://github.com/#{github_username}/#{project_name}
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
FIX (describe your package)
|
8
|
-
|
9
|
-
== FEATURES/PROBLEMS:
|
10
|
-
|
11
|
-
* FIX (list of features or problems)
|
12
|
-
|
13
|
-
== SYNOPSIS:
|
14
|
-
|
15
|
-
FIX (code sample of usage)
|
16
|
-
|
17
|
-
== REQUIREMENTS:
|
18
|
-
|
19
|
-
* None
|
20
|
-
|
21
|
-
== INSTALL:
|
22
|
-
|
23
|
-
* sudo gem install ruby-state-machine
|
24
|
-
|
25
|
-
== LICENSE:
|
26
|
-
|
27
|
-
(The MIT License)
|
28
|
-
|
29
|
-
Copyright (c) 2007-2009 Steven Miers
|
30
|
-
|
31
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
-
a copy of this software and associated documentation files (the
|
33
|
-
'Software'), to deal in the Software without restriction, including
|
34
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
-
permit persons to whom the Software is furnished to do so, subject to
|
37
|
-
the following conditions:
|
38
|
-
|
39
|
-
The above copyright notice and this permission notice shall be
|
40
|
-
included in all copies or substantial portions of the Software.
|
41
|
-
|
42
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
gem 'hoe', '>= 2.1.0'
|
3
|
-
require 'hoe'
|
4
|
-
require 'fileutils'
|
5
|
-
require './lib/ruby-state-machine'
|
6
|
-
|
7
|
-
Hoe.plugin :newgem
|
8
|
-
Hoe.plugin :website
|
9
|
-
# Hoe.plugin :cucumberfeatures
|
10
|
-
|
11
|
-
# Generate all the Rake tasks
|
12
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
-
$hoe = Hoe.spec 'ruby-state-machine' do
|
14
|
-
self.developer 'stevenmiers', 'steven.miers@gmail.com'
|
15
|
-
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
-
self.rubyforge_name = 'ruby-state-mach' #self.name # TODO this is default value
|
17
|
-
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'newgem/tasks'
|
22
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
-
|
24
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
-
# remove_task :default
|
26
|
-
# task :default => [:spec, :features]
|
data/config/website.yml
DELETED
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/ruby-state-machine.rb'}"
|
9
|
-
puts "Loading ruby-state-machine gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|