simplificator-fsm 0.3.7 → 0.3.8

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.markdown CHANGED
@@ -50,6 +50,8 @@ for suggestions!
50
50
  w.available_transition_names
51
51
  w.cool_down # again... it's the name of the transition
52
52
  w.state_of_material
53
+ w.state_liquid?
54
+ w.state_solid?
53
55
 
54
56
 
55
57
  ## Guards
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 3
3
- :patch: 7
3
+ :patch: 8
4
4
  :major: 0
data/lib/fsm/builder.rb CHANGED
@@ -17,6 +17,7 @@ module FSM
17
17
  raise ArgumentError.new('Block expected') unless block_given?
18
18
  self.instance_eval(&block)
19
19
  @machine.build_transition_methods
20
+ @machine.build_state_check_methods
20
21
  @machine
21
22
  end
22
23
 
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-fsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - simplificator