statemachine 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/statemachine/builder.rb
CHANGED
@@ -11,7 +11,7 @@ module Statemachine
|
|
11
11
|
# trans :unlocked, :pass, :locked, :lock
|
12
12
|
# end
|
13
13
|
#
|
14
|
-
# An optional statemachine
|
14
|
+
# An optional statemachine parameter may be passed in to modify
|
15
15
|
# an existing statemachine instance.
|
16
16
|
#
|
17
17
|
# Actions:
|
@@ -57,12 +57,13 @@ module Statemachine
|
|
57
57
|
module StateBuilding
|
58
58
|
attr_reader :subject
|
59
59
|
|
60
|
-
# Declares that the state responds to the
|
61
|
-
# The +event+
|
60
|
+
# Declares that the state responds to the specified event.
|
61
|
+
# The +event+ parameter should be a Symbol.
|
62
62
|
# The +destination_id+, which should also be a Symbol, is the id of the state
|
63
63
|
# that will event will transition into.
|
64
64
|
#
|
65
|
-
# The 3rd +action+
|
65
|
+
# The 3rd +action+ parameter is optional. Note that the action runs *before*
|
66
|
+
# the transition to the state specified in the 2nd parameter.
|
66
67
|
#
|
67
68
|
# sm = Statemachine.build do
|
68
69
|
# state :locked do
|
@@ -277,4 +278,4 @@ module Statemachine
|
|
277
278
|
end
|
278
279
|
end
|
279
280
|
|
280
|
-
end
|
281
|
+
end
|
@@ -33,6 +33,11 @@ module Statemachine
|
|
33
33
|
# is responsible for all the behavior.
|
34
34
|
attr_accessor :context
|
35
35
|
|
36
|
+
# A statemachine can be named. This is most useful when a program is running
|
37
|
+
# multiple machines with a tracer. The name is prepended to the tracer notices
|
38
|
+
# so that they can be matched to the correct statemachine.
|
39
|
+
attr_accessor :name
|
40
|
+
|
36
41
|
attr_reader :root #:nodoc:
|
37
42
|
|
38
43
|
# Should not be called directly. Instances of Statemachine::Statemachine are created
|
@@ -97,7 +102,10 @@ module Statemachine
|
|
97
102
|
end
|
98
103
|
|
99
104
|
def trace(message) #:nodoc:
|
100
|
-
|
105
|
+
if @tracer
|
106
|
+
prefix = @name ? "(#{@name}) " : ""
|
107
|
+
@tracer.puts("#{prefix}#{message}")
|
108
|
+
end
|
101
109
|
end
|
102
110
|
|
103
111
|
def get_state(id) #:nodoc:
|
data/lib/statemachine/version.rb
CHANGED
data/spec/sm_odds_n_ends_spec.rb
CHANGED
@@ -61,6 +61,41 @@ describe "State Machine Odds And Ends" do
|
|
61
61
|
@sm.state.should equal(:stuck)
|
62
62
|
end
|
63
63
|
|
64
|
+
it "traces output with name" do
|
65
|
+
io = StringIO.new
|
66
|
+
@sm.name = "Switch"
|
67
|
+
@sm.tracer = io
|
68
|
+
@sm.toggle
|
69
|
+
@sm.toggle
|
70
|
+
|
71
|
+
expected = StringIO.new
|
72
|
+
expected.puts "(Switch) Event: toggle"
|
73
|
+
expected.puts "(Switch) \texiting 'off' state"
|
74
|
+
expected.puts "(Switch) \tentering 'on' state"
|
75
|
+
expected.puts "(Switch) Event: toggle"
|
76
|
+
expected.puts "(Switch) \texiting 'on' state"
|
77
|
+
expected.puts "(Switch) \tentering 'off' state"
|
78
|
+
|
79
|
+
io.string.should == expected.string
|
80
|
+
end
|
81
|
+
|
82
|
+
it "traces output without name" do
|
83
|
+
io = StringIO.new
|
84
|
+
@sm.tracer = io
|
85
|
+
@sm.toggle
|
86
|
+
@sm.toggle
|
87
|
+
|
88
|
+
expected = StringIO.new
|
89
|
+
expected.puts "Event: toggle"
|
90
|
+
expected.puts "\texiting 'off' state"
|
91
|
+
expected.puts "\tentering 'on' state"
|
92
|
+
expected.puts "Event: toggle"
|
93
|
+
expected.puts "\texiting 'on' state"
|
94
|
+
expected.puts "\tentering 'off' state"
|
95
|
+
|
96
|
+
io.string.should == expected.string
|
97
|
+
end
|
98
|
+
|
64
99
|
end
|
65
100
|
|
66
101
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 1.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Micah Martin
|
@@ -14,7 +14,7 @@ autorequire: statemachine
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-06-17 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -90,7 +90,7 @@ rubyforge_project: statemachine
|
|
90
90
|
rubygems_version: 1.3.6
|
91
91
|
signing_key:
|
92
92
|
specification_version: 3
|
93
|
-
summary: Statemachine-1.
|
93
|
+
summary: Statemachine-1.2.0 - Statemachine Library for Ruby http://slagyr.github.com/statemachine
|
94
94
|
test_files:
|
95
95
|
- spec/action_invokation_spec.rb
|
96
96
|
- spec/builder_spec.rb
|