simplefsm 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/simplefsm.rb +25 -32
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 838b9cda4f9f7b0f591b871cc616ca400ad394f6
4
- data.tar.gz: ae9d5e7ec54dbfb8231dc60268badbcd886101c0
3
+ metadata.gz: f2a2b085fc53bb8bad80db05012653c5ec305808
4
+ data.tar.gz: 64d69c9349fff3f51c8ede74117b21596cf35afa
5
5
  SHA512:
6
- metadata.gz: cd41f768c7adc8096bb0b996ab030d7e27dea9b317258eaec4b690462b65b985f787c665f20c0ed9de1f9b09c105ebebc229b53ab2edc9ca0746b88a1eb5e454
7
- data.tar.gz: e540da439383cdd2b15becb409ca0e41ddad1d20ed8e3f34f450c2059470171acb2cb367e5cfabcf69ee24d3e6e147f0c22f3f63ca407d4b0b2d48f2c0267a3d
6
+ metadata.gz: 23e82bb0db0fa86ad0f754d2a018c07b1d56b0ea620a863fed0107d6f609f96837114e6da528edbb9398200323e3a4d70450a19552eb0c245199ca1c56386e14
7
+ data.tar.gz: 011724619fde75883c4dc803479e41280327690d36f1bf58c4ad99ac5f23ceea5803173357de1bd1ac09d9a51c0db7b0c0ffd124b732348fb1099a3d8a05cb40
@@ -14,7 +14,7 @@
14
14
  # License:: MIT License
15
15
 
16
16
  module SimpleFSM
17
- VERSION = '0.2.1'
17
+ VERSION = '0.2.3'
18
18
 
19
19
  # TransitionFactory instance is a temporary helper object
20
20
  # for making transitions from a transitions_for code block parameter
@@ -35,16 +35,22 @@ module SimpleFSM
35
35
 
36
36
  #Instance and class methods that are to be injected to the host class
37
37
  def initialize
38
- self.current_state = {}
38
+ # set_current_state nil
39
+ # self.set_current_state {}
39
40
  super
40
41
  end
41
42
 
42
- # start the machine
43
- def run
44
- self.current_state= @@states.first
45
- if current_state[:on]
46
- self.send(current_state[:on][:enter], nil) if current_state[:on].has_key?(:enter)
43
+ # start the machine only if it hasn't been started
44
+ def run *args
45
+ st = current_state args
46
+ if !st
47
+ st = @@states.first
48
+ if st[:on]
49
+ self.send(st[:on][:enter], args) if st[:on].has_key?(:enter)
50
+ end
51
+ set_current_state(st, args)
47
52
  end
53
+ st
48
54
  end
49
55
 
50
56
  # injecting the class methods for FSM definition
@@ -61,7 +67,6 @@ module SimpleFSM
61
67
  # - one method is defined for every event specified
62
68
  @@events.each do |ev|
63
69
  Kernel.send :define_method, ev do |*args|
64
- fsm_prepare_state args
65
70
 
66
71
  if args
67
72
  # If we have args here it must be an Array
@@ -72,14 +77,14 @@ module SimpleFSM
72
77
  args = []
73
78
  end
74
79
 
75
- if current_state.class == Hash
76
- st = current_state[:state]
80
+ if current_state(args).class == Hash
81
+ st = current_state(args)[:state]
77
82
  else
78
- st = current_state
83
+ st = current_state(args)
79
84
  end
80
85
 
81
86
  statetrans = @@transitions[st]
82
- uniquestates = []
87
+ # uniquestates = []
83
88
 
84
89
  if statetrans
85
90
  # Get all transitions for this event in the current state
@@ -141,7 +146,6 @@ module SimpleFSM
141
146
  end
142
147
  end
143
148
  end
144
- fsm_save_state args
145
149
  end
146
150
  end
147
151
  end
@@ -257,13 +261,13 @@ module SimpleFSM
257
261
  end
258
262
 
259
263
  # onexit, onenter = nil, nil
260
- onexit = current_state[:on][:exit] if current_state.has_key?(:on) and current_state[:on] and current_state[:on].has_key?(:exit)
264
+ onexit = current_state(args)[:on][:exit] if current_state(args).has_key?(:on) and current_state(args)[:on] and current_state(args)[:on].has_key?(:exit)
261
265
  if newstate[:on]
262
266
  onenter = newstate[:on][:enter] if newstate[:on].has_key?(:enter)
263
267
  end
264
268
 
265
269
  self.send(onexit, args) if onexit
266
- self.current_state = newstate
270
+ set_current_state newstate, args
267
271
  self.send(onenter, args) if onenter
268
272
  end
269
273
 
@@ -283,7 +287,7 @@ module SimpleFSM
283
287
  ev = []
284
288
  tr = @@transitions[st[:state]]
285
289
  ev << tr.map{|tran| tran[:event]} if tr
286
- ev.uniq!
290
+ ev.flatten!.uniq!
287
291
  ev
288
292
  end
289
293
 
@@ -297,31 +301,20 @@ module SimpleFSM
297
301
  #
298
302
  # #current_state is a private accessor that returns a full state object
299
303
  # #state is a public method that returns only the sate's name
300
- # #fsm_prepare_state method is called before and
301
- # #fsm_save_state method is called after actual state transition and all consequent actions.
302
304
 
303
- def current_state
305
+ def current_state *args
304
306
  @state
305
307
  end
306
308
 
307
- def current_state= (st)
309
+ def set_current_state(st, *args)
308
310
  @state = st
309
311
  end
310
312
 
311
- def state
312
- current_state[:state] #.to_sym
313
- end
314
-
315
- def fsm_prepare_state args
316
- current_state
317
- end
318
-
319
- def fsm_save_state args
320
- current_state
313
+ def state *args
314
+ current_state(args)[:state] #.to_sym
321
315
  end
322
316
 
323
317
  public :state
324
- private :current_state, :current_state=
325
- private :fsm_prepare_state, :fsm_save_state
318
+ private :current_state, :set_current_state
326
319
 
327
320
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplefsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edin Pjanic
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-16 00:00:00.000000000 Z
12
+ date: 2017-04-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple and lightweight domain specific language (DSL) for modeling
15
15
  finite state machines (FSM).