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/script/generate
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/generate'
|
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::Generate.new.run(ARGV)
|
data/script/txt2html
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
load File.dirname(__FILE__) + "/../Rakefile"
|
4
|
-
require 'rubyforge'
|
5
|
-
require 'redcloth'
|
6
|
-
require 'syntax/convertors/html'
|
7
|
-
require 'erb'
|
8
|
-
|
9
|
-
download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
|
10
|
-
version = $hoe.version
|
11
|
-
|
12
|
-
def rubyforge_project_id
|
13
|
-
RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
|
14
|
-
end
|
15
|
-
|
16
|
-
class Fixnum
|
17
|
-
def ordinal
|
18
|
-
# teens
|
19
|
-
return 'th' if (10..19).include?(self % 100)
|
20
|
-
# others
|
21
|
-
case self % 10
|
22
|
-
when 1: return 'st'
|
23
|
-
when 2: return 'nd'
|
24
|
-
when 3: return 'rd'
|
25
|
-
else return 'th'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Time
|
31
|
-
def pretty
|
32
|
-
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def convert_syntax(syntax, source)
|
37
|
-
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
38
|
-
end
|
39
|
-
|
40
|
-
if ARGV.length >= 1
|
41
|
-
src, template = ARGV
|
42
|
-
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
43
|
-
else
|
44
|
-
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
45
|
-
exit!
|
46
|
-
end
|
47
|
-
|
48
|
-
template = ERB.new(File.open(template).read)
|
49
|
-
|
50
|
-
title = nil
|
51
|
-
body = nil
|
52
|
-
File.open(src) do |fsrc|
|
53
|
-
title_text = fsrc.readline
|
54
|
-
body_text_template = fsrc.read
|
55
|
-
body_text = ERB.new(body_text_template).result(binding)
|
56
|
-
syntax_items = []
|
57
|
-
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
58
|
-
ident = syntax_items.length
|
59
|
-
element, syntax, source = $1, $2, $3
|
60
|
-
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
61
|
-
"syntax-temp-#{ident}"
|
62
|
-
}
|
63
|
-
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
64
|
-
body = RedCloth.new(body_text).to_html
|
65
|
-
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
66
|
-
end
|
67
|
-
stat = File.stat(src)
|
68
|
-
created = stat.ctime
|
69
|
-
modified = stat.mtime
|
70
|
-
|
71
|
-
$stdout << template.result(binding)
|
data/test/test_helper.rb
DELETED
data/test/test_state_machine.rb
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
#require "#{File.dirname(__FILE__)}/../init"
|
3
|
-
|
4
|
-
require 'ruby-state-machine/state_machine'
|
5
|
-
|
6
|
-
# Fixture for testing state machine:
|
7
|
-
class StateMachineFixture
|
8
|
-
include StateMachine
|
9
|
-
attr_accessor :test_val, :prev_test_val, :proc_val, :force_decide_nil, :name_for_decider
|
10
|
-
|
11
|
-
|
12
|
-
state_machine :states => [:a_state, :b_state, :c_state, :d_state], :events => [:w_event, :x_event, :y_event, :z_event]
|
13
|
-
state_transition :state=>:a_state, :event=>:w_event, :next=>{:state=>:b_state, :action=>lambda{|o, args| o.increment_value(5)} }
|
14
|
-
state_transition :state=>:a_state, :event=>:x_event, :next=>:c_state
|
15
|
-
state_transition :state=>:a_state, :event=>:y_event, :next=>:a_state
|
16
|
-
state_transition :state=>:a_state, :event=>:z_event, :next=>:b_state
|
17
|
-
|
18
|
-
state_transition :state=>:b_state, :event=>:w_event, :next=>:b_state
|
19
|
-
state_transition :state=>:b_state, :event=>:y_event, :next=>:c_state
|
20
|
-
state_transition :state=>:b_state, :event=>:z_event, :next=>:a_state
|
21
|
-
|
22
|
-
state_transition :state=>:c_state, :event=>:x_event, :next=>:b_state
|
23
|
-
state_transition :state=>:c_state, :event=>:y_event, :next=>{:state=>:a_state, :action=>lambda{|o, args| o.increment_value(-3)}}
|
24
|
-
|
25
|
-
state_transition :state=>:c_state, :event=>:w_event, :decider => :c_state_decider,
|
26
|
-
:next=>[
|
27
|
-
{:state=>:a_state, :action=>lambda{|o, args| o.increment_value(7)} },
|
28
|
-
{:state=>:b_state, :action=>lambda{|o, args| o.increment_value(-10)} }
|
29
|
-
]
|
30
|
-
|
31
|
-
state_transition :state=>:c_state, :event=>:z_event , :decider => :named_action_decider,
|
32
|
-
:next=>[
|
33
|
-
{:name=>"foo", :state=>:a_state, :action=>lambda{|o, args| o.increment_value(7)} },
|
34
|
-
{:name=>"bar", :state=>:d_state, :action=>lambda{|o, args| o.increment_value(-10)} }
|
35
|
-
]
|
36
|
-
|
37
|
-
state_transition :state=>:d_state, :event=>:x_event, :next=>:stay
|
38
|
-
|
39
|
-
def initialize
|
40
|
-
super
|
41
|
-
@test_val = nil
|
42
|
-
@proc_val = 0
|
43
|
-
@force_decide_nil = false
|
44
|
-
@name_for_decider = "foo"
|
45
|
-
end
|
46
|
-
|
47
|
-
def increment_value(by)
|
48
|
-
@proc_val += by
|
49
|
-
end
|
50
|
-
|
51
|
-
def bush(term)
|
52
|
-
@prev_test_val = @test_val
|
53
|
-
@test_val=term
|
54
|
-
send_event(:w_event)
|
55
|
-
end
|
56
|
-
|
57
|
-
def c_state_decider(args)
|
58
|
-
if @force_decide_nil
|
59
|
-
# Hack to test nil decider:
|
60
|
-
nil
|
61
|
-
else
|
62
|
-
refined = (@test_val and @prev_test_val and @test_val.index(@prev_test_val)==0)
|
63
|
-
refined ? :b_state : :a_state
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def named_action_decider(args)
|
68
|
-
@name_for_decider
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
# Test state machine:
|
74
|
-
class StateMachineTest < Test::Unit::TestCase
|
75
|
-
|
76
|
-
def test_states
|
77
|
-
assert_equal(:d_state, StateMachineFixture.states.last)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_events
|
81
|
-
assert_equal(:w_event, StateMachineFixture.events.first)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_next_states
|
85
|
-
assert_equal(:b_state, StateMachineFixture.next_state(:a_state, :w_event))
|
86
|
-
assert_equal(:c_state, StateMachineFixture.next_state(:a_state, :x_event))
|
87
|
-
assert_equal(:b_state, StateMachineFixture.next_state(:b_state, :w_event))
|
88
|
-
assert_equal(:a_state, StateMachineFixture.next_state(:b_state, :z_event))
|
89
|
-
assert_equal(:a_state, StateMachineFixture.next_state(:c_state, :y_event))
|
90
|
-
assert_equal(:b_state, StateMachineFixture.next_state(:c_state, :x_event))
|
91
|
-
assert_nil(StateMachineFixture.next_state(:b_state, :x_event))
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_event_sending
|
95
|
-
sm = StateMachineFixture.new
|
96
|
-
assert_equal(:a_state, sm.current_state)
|
97
|
-
sm.send_event(:w_event)
|
98
|
-
|
99
|
-
assert_equal(:b_state, sm.current_state)
|
100
|
-
assert_raise(StateMachine::InvalidStateError){sm.send_event(:x_event)}
|
101
|
-
|
102
|
-
sm.send_event(:w_event)
|
103
|
-
assert_equal(:b_state, sm.current_state)
|
104
|
-
|
105
|
-
sm.send_event(:z_event)
|
106
|
-
assert_equal(:a_state, sm.current_state)
|
107
|
-
|
108
|
-
sm.send_event(:x_event)
|
109
|
-
assert_equal(:c_state, sm.current_state)
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_action_calling
|
113
|
-
sm = StateMachineFixture.new
|
114
|
-
assert_equal(0, sm.proc_val)
|
115
|
-
assert_equal(:a_state, sm.current_state)
|
116
|
-
sm.send_event(:w_event)
|
117
|
-
assert_equal(5, sm.proc_val)
|
118
|
-
|
119
|
-
sm.send_event(:y_event)
|
120
|
-
assert_equal(5, sm.proc_val)
|
121
|
-
|
122
|
-
sm.send_event(:y_event)
|
123
|
-
assert_equal(2, sm.proc_val)
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_decider
|
127
|
-
sm = StateMachineFixture.new
|
128
|
-
assert_equal(:a_state, sm.current_state)
|
129
|
-
sm.send_event(:x_event)
|
130
|
-
sm.bush("foo")
|
131
|
-
assert_equal(:a_state, sm.current_state)
|
132
|
-
sm.bush("foobar")
|
133
|
-
assert_equal(:b_state, sm.current_state)
|
134
|
-
sm.send_event(:y_event)
|
135
|
-
sm.bush("barfoo")
|
136
|
-
assert_equal(:a_state, sm.current_state)
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_nil_decider
|
140
|
-
sm = StateMachineFixture.new
|
141
|
-
assert_equal(:a_state, sm.current_state)
|
142
|
-
sm.send_event(:x_event)
|
143
|
-
assert_equal(:c_state, sm.current_state)
|
144
|
-
sm.force_decide_nil=true
|
145
|
-
assert_raise(StateMachine::InvalidStateError){sm.send_event(:w_event)}
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_multiple_actions_without_decider
|
149
|
-
assert_raise(ArgumentError) do
|
150
|
-
StateMachineFixture.state_transition :state=>:c_state, :event=>:z_event, #:decider => :c_state_decider,
|
151
|
-
:next=>[
|
152
|
-
{:state=>:a_state, :action=>lambda{|o, args| o.increment_value(7)} },
|
153
|
-
{:state=>:b_state, :action=>lambda{|o, args| o.increment_value(-10)} }
|
154
|
-
]
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_named_actions_in_decider
|
159
|
-
sm = StateMachineFixture.new
|
160
|
-
assert_equal(:a_state, sm.current_state)
|
161
|
-
sm.send_event(:x_event)
|
162
|
-
assert_equal(:c_state, sm.current_state)
|
163
|
-
sm.send_event(:z_event)
|
164
|
-
|
165
|
-
# Default value (foo) for named decider:
|
166
|
-
assert_equal(:a_state, sm.current_state)
|
167
|
-
|
168
|
-
# Back to a_state:
|
169
|
-
sm.send_event(:x_event)
|
170
|
-
assert_equal(:c_state, sm.current_state)
|
171
|
-
|
172
|
-
# Alt value (bar) for named decider:
|
173
|
-
sm.name_for_decider = 'bar'
|
174
|
-
sm.send_event(:z_event)
|
175
|
-
assert_equal(:d_state, sm.current_state)
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_stay_state
|
179
|
-
sm = StateMachineFixture.new
|
180
|
-
|
181
|
-
# Get to :d state:
|
182
|
-
sm.send_event(:x_event)
|
183
|
-
sm.name_for_decider = 'bar'
|
184
|
-
sm.send_event(:z_event)
|
185
|
-
assert_equal(:d_state, sm.current_state)
|
186
|
-
|
187
|
-
# Send event & make sure we are still in :d state:
|
188
|
-
sm.send_event(:x_event)
|
189
|
-
assert_equal(:d_state, sm.current_state)
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_event_history
|
193
|
-
sm = StateMachineFixture.new
|
194
|
-
assert_equal(0, sm.event_history.size)
|
195
|
-
sm.send_event(:x_event)
|
196
|
-
assert_equal(1, sm.event_history.size)
|
197
|
-
assert_equal([:x_event], sm.event_history)
|
198
|
-
sm.send_event(:y_event)
|
199
|
-
assert_equal(2, sm.event_history.size)
|
200
|
-
assert_equal([:x_event, :y_event], sm.event_history)
|
201
|
-
sm.send_event(:y_event)
|
202
|
-
assert_equal(3, sm.event_history.size)
|
203
|
-
assert_equal([:x_event, :y_event, :y_event], sm.event_history)
|
204
|
-
|
205
|
-
# Should max out at 10:
|
206
|
-
15.times{sm.send_event(:z_event)}
|
207
|
-
assert_equal(10, sm.event_history.size)
|
208
|
-
assert_equal(Array.new(10, :z_event), sm.event_history)
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
data/website/index.html
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
-
<title>
|
8
|
-
ruby-state-machine
|
9
|
-
</title>
|
10
|
-
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
-
<style>
|
12
|
-
|
13
|
-
</style>
|
14
|
-
<script type="text/javascript">
|
15
|
-
window.onload = function() {
|
16
|
-
settings = {
|
17
|
-
tl: { radius: 10 },
|
18
|
-
tr: { radius: 10 },
|
19
|
-
bl: { radius: 10 },
|
20
|
-
br: { radius: 10 },
|
21
|
-
antiAlias: true,
|
22
|
-
autoPad: true,
|
23
|
-
validTags: ["div"]
|
24
|
-
}
|
25
|
-
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
-
versionBox.applyCornersToAll();
|
27
|
-
}
|
28
|
-
</script>
|
29
|
-
</head>
|
30
|
-
<body>
|
31
|
-
<div id="main">
|
32
|
-
|
33
|
-
<h1>ruby-state-machine</h1>
|
34
|
-
<div class="sidebar">
|
35
|
-
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/ruby-state-mach"; return false'>
|
36
|
-
<p>Get Version</p>
|
37
|
-
<a href="http://rubyforge.org/projects/ruby-state-mach" class="numbers">0.0.3</a>
|
38
|
-
</div>
|
39
|
-
</div>
|
40
|
-
<p>An enhanced state machine gem for ruby (doesn’t require Rails). Provides more robust <span class="caps">DSL</span> state declaration syntax than other state machines. Multiple “actions” per event (i.e., next state, labmda, or a “decider”. Fully unit-tested & documented. Has been used in production for over 2 years.</p>
|
41
|
-
<h2>Installing</h2>
|
42
|
-
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">ruby</span><span class="punct">-</span><span class="ident">state</span><span class="punct">-</span><span class="ident">machine</span></pre></p>
|
43
|
-
<h2>Demonstration of usage<br />
|
44
|
-
<pre class='syntax'>
|
45
|
-
<span class="keyword">class </span><span class="class">SampleMachine</span>
|
46
|
-
<span class="ident">include</span> <span class="constant">StateMachine</span>
|
47
|
-
<span class="ident">state_machine</span> <span class="symbol">:states</span> <span class="punct">=></span> <span class="punct">[</span><span class="symbol">:a_state</span><span class="punct">,</span> <span class="symbol">:b_state</span><span class="punct">,</span> <span class="symbol">:c_state</span><span class="punct">,</span> <span class="symbol">:d_state</span><span class="punct">],</span> <span class="symbol">:events</span> <span class="punct">=></span> <span class="punct">[</span><span class="symbol">:w_event</span><span class="punct">,</span> <span class="symbol">:x_event</span><span class="punct">,</span> <span class="symbol">:y_event</span><span class="punct">,</span> <span class="symbol">:z_event</span><span class="punct">]</span>
|
48
|
-
<span class="ident">state_transition</span> <span class="symbol">:state=</span><span class="punct">></span><span class="symbol">:a_state</span><span class="punct">,</span> <span class="symbol">:event=</span><span class="punct">></span><span class="symbol">:x_event</span><span class="punct">,</span> <span class="symbol">:next=</span><span class="punct">></span><span class="symbol">:c_state</span>
|
49
|
-
<span class="ident">state_transition</span> <span class="symbol">:state=</span><span class="punct">></span><span class="symbol">:a_state</span><span class="punct">,</span> <span class="symbol">:event=</span><span class="punct">></span><span class="symbol">:y_event</span><span class="punct">,</span> <span class="symbol">:next=</span><span class="punct">></span><span class="symbol">:a_state</span>
|
50
|
-
<span class="ident">state_transition</span> <span class="symbol">:state=</span><span class="punct">></span><span class="symbol">:a_state</span><span class="punct">,</span> <span class="symbol">:event=</span><span class="punct">></span><span class="symbol">:z_event</span><span class="punct">,</span> <span class="symbol">:next=</span><span class="punct">></span><span class="symbol">:b_state</span>
|
51
|
-
|
52
|
-
<span class="ident">state_transition</span> <span class="symbol">:state=</span><span class="punct">></span><span class="symbol">:b_state</span><span class="punct">,</span> <span class="symbol">:event=</span><span class="punct">></span><span class="symbol">:w_event</span><span class="punct">,</span> <span class="symbol">:next=</span><span class="punct">></span><span class="symbol">:b_state</span>
|
53
|
-
<span class="ident">state_transition</span> <span class="symbol">:state=</span><span class="punct">></span><span class="symbol">:b_state</span><span class="punct">,</span> <span class="symbol">:event=</span><span class="punct">></span><span class="symbol">:y_event</span><span class="punct">,</span> <span class="symbol">:next=</span><span class="punct">></span><span class="symbol">:c_state</span>
|
54
|
-
<span class="ident">state_transition</span> <span class="symbol">:state=</span><span class="punct">></span><span class="symbol">:b_state</span><span class="punct">,</span> <span class="symbol">:event=</span><span class="punct">></span><span class="symbol">:z_event</span><span class="punct">,</span> <span class="symbol">:next=</span><span class="punct">></span><span class="symbol">:a_state</span>
|
55
|
-
|
56
|
-
<span class="ident">state_transition</span> <span class="symbol">:state=</span><span class="punct">></span><span class="symbol">:c_state</span><span class="punct">,</span> <span class="symbol">:event=</span><span class="punct">></span><span class="symbol">:x_event</span><span class="punct">,</span> <span class="symbol">:next=</span><span class="punct">></span><span class="symbol">:b_state</span>
|
57
|
-
<span class="keyword">end</span>
|
58
|
-
|
59
|
-
<span class="ident">sm</span> <span class="punct">=</span> <span class="constant">SampleMachine</span><span class="punct">.</span><span class="ident">new</span>
|
60
|
-
<span class="ident">assert_equal</span><span class="punct">(</span><span class="symbol">:a_state</span><span class="punct">,</span> <span class="ident">sm</span><span class="punct">.</span><span class="ident">current_state</span><span class="punct">)</span>
|
61
|
-
<span class="ident">sm</span><span class="punct">.</span><span class="ident">send_event</span><span class="punct">(</span><span class="symbol">:x_event</span><span class="punct">)</span>
|
62
|
-
<span class="ident">assert_equal</span><span class="punct">(</span><span class="symbol">:c_state</span><span class="punct">,</span> <span class="ident">sm</span><span class="punct">.</span><span class="ident">current_state</span><span class="punct">)</span>
|
63
|
-
|
64
|
-
</pre></h2>
|
65
|
-
<p>For examples of other functionality, including branching, deciders, lambdas, etc, see test/test_state_machine.</p>
|
66
|
-
<h2>Forum</h2>
|
67
|
-
<p><a href="http://groups.google.com/group/ruby-state-machine">http://groups.google.com/group/ruby-state-machine</a></p>
|
68
|
-
<h2>How to submit patches</h2>
|
69
|
-
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
70
|
-
<p><span class="caps">TODO</span> – pick <span class="caps">SVN</span> or Git instructions</p>
|
71
|
-
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/ruby-state-machine/trunk</code> for anonymous access.</p>
|
72
|
-
<p><span class="caps">OOOORRRR</span></p>
|
73
|
-
<p>You can fetch the source from either:</p>
|
74
|
-
<ul>
|
75
|
-
<li>rubyforge: <a href="http://rubyforge.org/scm/?group_id=8855">http://rubyforge.org/scm/?group_id=8855</a></li>
|
76
|
-
</ul>
|
77
|
-
<pre>git clone git://rubyforge.org/ruby-state-machine.git</pre>
|
78
|
-
<ul>
|
79
|
-
<li>github: <a href="http://github.com/GITHUB_USERNAME/ruby-state-machine/tree/master">http://github.com/GITHUB_USERNAME/ruby-state-machine/tree/master</a></li>
|
80
|
-
</ul>
|
81
|
-
<pre>git clone git://github.com/GITHUB_USERNAME/ruby-state-machine.git</pre>
|
82
|
-
<p><span class="caps">TODO</span> – add “github_username: username” to ~/.rubyforge/user-config.yml and newgem will reuse it for future projects.</p>
|
83
|
-
<ul>
|
84
|
-
<li>gitorious: <a href="git://gitorious.org/ruby-state-machine/mainline.git">git://gitorious.org/ruby-state-machine/mainline.git</a></li>
|
85
|
-
</ul>
|
86
|
-
<pre>git clone git://gitorious.org/ruby-state-machine/mainline.git</pre>
|
87
|
-
<h3>Build and test instructions</h3>
|
88
|
-
<pre>cd ruby-state-machine
|
89
|
-
rake test
|
90
|
-
</pre>
|
91
|
-
<h2>License</h2>
|
92
|
-
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
93
|
-
<h2>Contact</h2>
|
94
|
-
<p>Comments are welcome. Send an email to <a href="mailto:steven.miers@gmail.com"><span class="caps">FIXME</span> full name</a> via the <a href="http://groups.google.com/group/ruby-state-machine">forum</a></p>
|
95
|
-
<p class="coda">
|
96
|
-
<a href="steven.miers@gmail.com">FIXME full name</a>, 18th August 2009<br>
|
97
|
-
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
98
|
-
</p>
|
99
|
-
</div>
|
100
|
-
|
101
|
-
<!-- insert site tracking codes here, like Google Urchin -->
|
102
|
-
|
103
|
-
</body>
|
104
|
-
</html>
|
data/website/index.txt
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
h1. ruby-state-machine
|
2
|
-
|
3
|
-
An enhanced state machine gem for ruby (doesn't require Rails). Provides more robust DSL state declaration syntax than other state machines. Multiple "actions" per event (i.e., next state, labmda, or a "decider". Fully unit-tested & documented. Has been used in production for over 2 years.
|
4
|
-
|
5
|
-
h2. Installing
|
6
|
-
|
7
|
-
<pre syntax="ruby">sudo gem install ruby-state-machine</pre>
|
8
|
-
|
9
|
-
h2. Demonstration of usage
|
10
|
-
<pre syntax="ruby">
|
11
|
-
class SampleMachine
|
12
|
-
include StateMachine
|
13
|
-
state_machine :states => [:a_state, :b_state, :c_state, :d_state], :events => [:w_event, :x_event, :y_event, :z_event]
|
14
|
-
state_transition :state=>:a_state, :event=>:x_event, :next=>:c_state
|
15
|
-
state_transition :state=>:a_state, :event=>:y_event, :next=>:a_state
|
16
|
-
state_transition :state=>:a_state, :event=>:z_event, :next=>:b_state
|
17
|
-
|
18
|
-
state_transition :state=>:b_state, :event=>:w_event, :next=>:b_state
|
19
|
-
state_transition :state=>:b_state, :event=>:y_event, :next=>:c_state
|
20
|
-
state_transition :state=>:b_state, :event=>:z_event, :next=>:a_state
|
21
|
-
|
22
|
-
state_transition :state=>:c_state, :event=>:x_event, :next=>:b_state
|
23
|
-
end
|
24
|
-
|
25
|
-
sm = SampleMachine.new
|
26
|
-
assert_equal(:a_state, sm.current_state)
|
27
|
-
sm.send_event(:x_event)
|
28
|
-
assert_equal(:c_state, sm.current_state)
|
29
|
-
|
30
|
-
</pre>
|
31
|
-
|
32
|
-
For examples of other functionality, including branching, deciders, lambdas, etc, see test/test_state_machine.
|
33
|
-
|
34
|
-
h2. Forum
|
35
|
-
|
36
|
-
"http://groups.google.com/group/ruby-state-machine":http://groups.google.com/group/ruby-state-machine
|
37
|
-
|
38
|
-
h2. How to submit patches
|
39
|
-
|
40
|
-
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
41
|
-
|
42
|
-
h3. Build and test instructions
|
43
|
-
|
44
|
-
<pre>cd ruby-state-machine
|
45
|
-
rake test
|
46
|
-
</pre>
|
47
|
-
|
48
|
-
h2. License
|
49
|
-
|
50
|
-
This code is free to use under the terms of the MIT license.
|
51
|
-
|
52
|
-
h2. Contact
|
53
|
-
|
54
|
-
Comments are welcome. Send an email to "FIXME full name":mailto:steven.miers@gmail.com via the "forum":http://groups.google.com/group/ruby-state-machine
|
55
|
-
|