simplificator-fsm 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -0
- data/VERSION.yml +1 -1
- data/lib/fsm/builder.rb +1 -0
- data/lib/fsm/machine.rb +15 -0
- data/test/ar_test.rb +8 -0
- metadata +1 -1
data/README.markdown
CHANGED
data/VERSION.yml
CHANGED
data/lib/fsm/builder.rb
CHANGED
data/lib/fsm/machine.rb
CHANGED
@@ -72,6 +72,13 @@ module FSM
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
def build_state_check_methods
|
76
|
+
self.states.each do |state|
|
77
|
+
define_state_check_method(state)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
75
82
|
# Lookup a State by it's name
|
76
83
|
# raises ArgumentError if state can not be found unless quiet is set to true
|
77
84
|
def state_for_name(name, quiet = false)
|
@@ -83,6 +90,14 @@ module FSM
|
|
83
90
|
|
84
91
|
private
|
85
92
|
|
93
|
+
def define_state_check_method(state)
|
94
|
+
@target_class.instance_eval do
|
95
|
+
define_method("state_#{state.name}?") do
|
96
|
+
Machine.get_current_state_name(self).to_s == state.name.to_s
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
86
101
|
# defines a transition method on the target class.
|
87
102
|
# this is the method triggering the state change.
|
88
103
|
#
|
data/test/ar_test.rb
CHANGED
@@ -28,5 +28,13 @@ class ArTest < Test::Unit::TestCase
|
|
28
28
|
o = Order.find(o.id)
|
29
29
|
assert_equal :delivered, o.state
|
30
30
|
end
|
31
|
+
|
32
|
+
|
33
|
+
should 'have state check methods' do
|
34
|
+
o = Order.new
|
35
|
+
assert o.state_open?
|
36
|
+
o.deliver
|
37
|
+
assert o.state_delivered?
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|