finite_machine 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e70496d1e626025a2c8ad75e0c66f5dfacb5d1c5
4
- data.tar.gz: 30b266427c011d60d77254c0740d34c843a55732
3
+ metadata.gz: d61855a6c9bcf4a134d260eed0b9926250c165e2
4
+ data.tar.gz: 8700fa2dccb31e106fa9fa7769466d4a4b22fc24
5
5
  SHA512:
6
- metadata.gz: d7e2d93b571c333c64ec880d3665abdf1ca65b8abd4ba2389b7d6451ad179e4aca67c42811829bdb6cad23a61993efdaf1c225cb6927572222b6bb76828bec88
7
- data.tar.gz: d72998f62c65ed6c5f74021926db45e99cfaf065665627f4a8f2e485215397c712326d80a36aa20e281879bb9d79dcab5f670d0ca71736d7bc6e09c4edb7182a
6
+ metadata.gz: 199260fd23c214d00e371a803178ee8693fb9f236ca3e68f08a59f181f8d8f251e9a5e340f60deb2b5894358517bf892a8410e6f97e80a717b12ca280c3e50b6
7
+ data.tar.gz: 53371bc2d260b5c9e2cf48c03769891540227b967f85039aa878731a9efe6b3be68dffce30a2b45375be409486449d410f3d521eb691fa8b9bc3296982c58402
data/.rspec CHANGED
@@ -2,3 +2,4 @@
2
2
  --format progress
3
3
  --order random
4
4
  --warnings
5
+ --require spec_helper
@@ -1,19 +1,22 @@
1
+ ---
1
2
  language: ruby
2
- bundler_args: --without yard guard benchmarks
3
+ sudo: false
4
+ cache: bundler
5
+ bundler_args: --without yard benchmarks
3
6
  script: "bundle exec rake ci"
4
7
  rvm:
5
8
  - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
8
- - 2.2.0
9
+ - 2.0
10
+ - 2.1
11
+ - 2.2
9
12
  - ruby-head
13
+ - rbx-2
10
14
  matrix:
11
15
  include:
12
16
  - rvm: jruby-19mode
13
17
  - rvm: jruby-20mode
14
18
  - rvm: jruby-21mode
15
19
  - rvm: jruby-head
16
- - rvm: rbx-2
17
20
  allow_failures:
18
21
  - rvm: ruby-head
19
22
  - rvm: jruby-head
@@ -1,8 +1,18 @@
1
- 0.11.0 (Oct 11, 2015)
1
+ # Change Log
2
2
 
3
+ ## [v0.11.1] - 2015-12-17
4
+
5
+ ### Fixed
6
+ * Fix cancelling callbacks for halted transition by craiglittle
7
+
8
+ ## [v0.11.0] - 2015-10-11
9
+
10
+ ### Added
3
11
  * Add UndefinedTransition to mark self transition(e.i. no transition found)
4
12
  * Add StateDefinition for state query methods
5
13
  * Add #trigger and #trigger! to StateMachine to allow manual firing of events and split between dangerous and non-dangerous versions of api.
14
+
15
+ ### Changed
6
16
  * Change ThreadContext to require per thread setup
7
17
  * Change Transition to stop relying on global transitions
8
18
  * Change EventChain to manage all internal transitions
@@ -11,67 +21,91 @@
11
21
  * Change HookEvent to accept event name and from state
12
22
  * Remove Event class as duplicate of Transition
13
23
  * Remove unnecessary checks for StateMachine#can?
24
+
25
+ ### Fixed
14
26
  * Fix bug in Transition with current transition matching
15
27
  * Fix bug in Observer with cancelling inside event callback
16
28
 
17
- 0.10.2 (July 5, 2015)
29
+ ## [v0.10.2] - 2015-07-05
18
30
 
19
- * Fix to run 'on_after' callbacks even when event cancalled by @craiglittle
20
- * Fix to cancel transition when no matching choice is found by @craiglittle
31
+ ### Changed
21
32
  * Change StateParser #parse method
22
33
  * Change EventBuilder to EventDefinition and invert dependencies
23
34
  * Change Event#call to #trigger
24
35
  * Change Transition#call to #execute
25
36
 
26
- 0.10.1 (May 24, 2015)
37
+ ### Fixed
38
+ * Fix to run 'on_after' callbacks even when event cancalled by @craiglittle
39
+ * Fix to cancel transition when no matching choice is found by @craiglittle
27
40
 
41
+ ## [v0.10.1] - 2015-05-24
42
+
43
+ ### Added
28
44
  * Add ability to inherit state machine definitions
29
45
  * Add Env class for holiding machine envionment references
46
+
47
+ ### Changed
30
48
  * Change DSL to delegate calls to machine instance
31
49
  * Change ChoiceMerger to use machine directly
32
50
 
33
- 0.10.0 (November 16, 2014)
51
+ ## [v0.10.0] - 2014-11-16
34
52
 
53
+ ### Added
35
54
  * Add #alias_target to allow renaming of target object by @reggieb
36
- * Fix issue with async calls passing wrong arguments to conditionals
37
- * Change TransitionEvent, AsyncCall to be immutable
38
55
  * Add :log_transitions option for easy transition debugging
56
+
57
+ ### Changed
58
+ * Change TransitionEvent, AsyncCall to be immutable
39
59
  * Increase test coverage to 99%
40
60
 
41
- 0.9.2 (September 27, 2014)
61
+ ### Fixed
62
+ * Fix issue with async calls passing wrong arguments to conditionals
63
+
64
+ ## [v0.9.2] - 2014-09-27
42
65
 
66
+ ### Changed
43
67
  * Removes use of class variable to share Sync by @reggieb
68
+
69
+ ### Fixed
44
70
  * Fix observer to differentiate between any state and any event
45
71
  * [#23] Fix transition to correctly set :from and :to parameters for :any state
46
72
  * [#25] Fix passing parameters to choice events with same named events
47
73
  * Fix choice pseudostate to work with :any state
48
74
 
49
- 0.9.1 (August 10, 2014)
75
+ ## [v0.9.1] - 2014-08-10
50
76
 
77
+ ### Added
51
78
  * Add TransitionBuilder to internally build transitions from states
52
- * Fix #choice to allow for multiple from states
53
79
  * Add #current? to Transition to determine if matches from state
54
80
  * Add #select_choice_transition to EventsChain to determine matching choice transition
81
+
82
+ ### Fixed
83
+ * Fix #choice to allow for multiple from states
55
84
  * Fix #choice to work with same named events
56
85
 
57
- 0.9.0 (August 3, 2014)
86
+ ## [v0.9.0] 2014-08-03
58
87
 
88
+ ### Added
59
89
  * Add Definition class to allow to define standalone state machine
60
- * Upgrade RSpec dependency and refactor specs
90
+ * Add #build method to HookEvent
91
+
92
+ ### Changed
61
93
  * Change initial helper to simply state name with options
62
94
  * Change HookEvent to be immutable and extend comparison
63
95
  * Change Event to be immutable and extend comparison
64
- * Add #build method to HookEvent
65
96
  * Change finished? to terminated? and allow for multiple terminal states
66
97
  * Change to require explicit context to call target methods
98
+ * Upgrade RSpec dependency and refactor specs
67
99
 
68
- 0.8.1 (July 5, 2014)
100
+ ## [v0.8.1] - 2014-07-05
69
101
 
102
+ ### Added
70
103
  * Add EventsChain to handle internal events logic
71
104
  * Add EventBuilder to handle events construction
72
105
 
73
- 0.8.0 (June 22, 2014)
106
+ ## [v0.8.0] - 2014-06-22
74
107
 
108
+ ### Added
75
109
  * Add silent option for state machine events to allow turning on/off
76
110
  selectively callbacks
77
111
  * Ensure that can? & cannot? take into account conditionl logic applied
@@ -80,83 +114,132 @@
80
114
  * Add ability to do dynamic conditional branching using the choice DSL or
81
115
  grouped events with different outgoing transitions [solves #13 and #6 issue]
82
116
 
83
- 0.7.1 (June 8, 2014)
117
+ ## [v0.7.1] - 2014-06-08
84
118
 
119
+ ### Changed
85
120
  * Change to relax callback name checks to allow for duplicate state and event names
86
121
  * Change so that transition to initial state triggers callbacks
87
122
 
88
- 0.7.0 (May 26, 2014)
123
+ ## [v0.7.0] - 2014-05-26
89
124
 
90
- * Change Event to EventHook for callback events
125
+ ### Added
91
126
  * Add Event to hold the logic for event specification
92
- * Fix issue #8 to preserve conditionals between event specifications
127
+ * Add string inspection to hooks
128
+ * Add check for callback name conflicts
129
+
130
+ ### Changed
131
+ * Change Event to EventHook for callback events
93
132
  * Change to allow for self-transition - fixes issue #9
94
133
  * Change to detect attempt to overwrite already defined method - fixes issue #10
95
- * Fix #respond_to on state machine to include observer
96
- * Add string inspection to hooks
97
- * Fix observer missing methods resolution
98
134
  * Change to separate state and event callbacks. Introduced on_enter, on_before,
99
135
  once_on_enter, once_on_before new event callbacks.
100
136
  * Change generic callbacks to default to any state for on_enter, on_transition,
101
137
  on_exit and any event for on_before and on_after
102
- * Add check for callback name conflicts
103
- * Ensure proper callback lifecycle
138
+ * Change to ensure proper callback lifecycle
104
139
 
105
- 0.6.1 (May 10, 2014)
140
+ ### Fixed
141
+ * Fix issue #8 to preserve conditionals between event specifications
142
+ * Fix #respond_to on state machine to include observer
143
+ * Fix observer missing methods resolution
106
144
 
145
+ ### [v0.6.1] - 2014-05-10
146
+
147
+ ### Fixed
107
148
  * Fix stdlib requirement
108
149
 
109
- 0.6.0 (May 10, 2014)
150
+ ### [v0.6.0] - 2014-05-10
110
151
 
152
+ ### Added
111
153
  * Add StateParser to allow for grouping transition under same event name
112
- * Change Transition to store a map of transition for a given event
113
154
  * Add abilility to correctly extract :to state for Transition instance
155
+
156
+ ### Changed
157
+ * Change Transition to store a map of transition for a given event
158
+
159
+ ### Fixed
114
160
  * Fix bug #6 with incorrect TransitionEvent payload information
115
161
 
116
- 0.5.0 (April 28, 2014)
162
+ ## [v0.5.0] - 2014-04-28
117
163
 
164
+ ### Added
165
+ * Add generic Listener interface
166
+ * Add ability to fire callbacks asynchronously
167
+ * Add initial state storage
168
+
169
+ ### Changed
118
170
  * Change to allow for machine to be constructed as plain object
119
171
  * Allow for :initial, :terminal and :target to be machine parameters
120
- * Add generic Listener interface
121
172
  * Change EventQueue to allow for subscription
122
173
  * Increase test coverage to 98%
123
174
  * Change to allow access to target inside machine dsl
124
- * Add ability to fire callbacks asynchronously
125
- * Add initial state storage
126
175
 
127
- 0.4.0 (April 13, 2014)
176
+ ## [v0.4.0] - 2014-04-13
128
177
 
129
- * Change initial state to stop firing event notification
130
- * Fix initial to accept any state object
178
+ ### Added
131
179
  * Add logger
132
180
  * Add ability to cancel transitions inside callbacks
133
- * Fix proc conditions to accept aditional arguments
134
- * Increase test coverage to 97%
135
181
  * Add ability to force transitions
136
182
 
137
- 0.3.0 (March 30, 2014)
183
+ ### Changed
184
+ * Change initial state to stop firing event notification
185
+ * Increase test coverage to 97%
138
186
 
139
- * Move development dependencies to Gemfile
140
- * Increase test coverage to 95%
141
- * Fix bug with event methods dynamic redefinition
142
- * Change attr_threadsafe to accept default values
143
- * Fix observer respond_to
187
+ ### Fixed
188
+ * Fix initial to accept any state object
189
+ * Fix proc conditions to accept aditional arguments
190
+
191
+ ## [v0.3.0] - 2014-03-30
192
+
193
+ ### Added
144
194
  * Add ability to specify callbacks on machine instance
145
195
  * Add once_on type of callback
146
196
  * Add off method for removing callbacks
147
197
  * Add async method to state_machine for asynchronous events firing
148
- * Fix Callable to correctly forward arguments
149
198
  * Add state helpers fsm.green? to allow easily check current state
150
199
 
151
- 0.2.0 (March 01, 2014)
200
+ ### Changed
201
+ * Change attr_threadsafe to accept default values
202
+ * Move development dependencies to Gemfile
203
+ * Increase test coverage to 95%
152
204
 
153
- * Ensure correct transition object state
154
- * Add methods synchronization for thread safety
155
- * Fix bug - callback event object returns correct from state
156
- * Add ability to define custom initial event
157
- * Add hooks class for callbacks registration
158
- * Extend threadable accessors
205
+ ### Fixed
206
+ * Fix bug with event methods dynamic redefinition
207
+ * Fix observer respond_to
208
+ * Fix Callable to correctly forward arguments
209
+
210
+ ## [v0.2.0] - 2014-03-01
211
+
212
+ ### Added
159
213
  * Add generic state and event listeners
160
214
  * Add target to allow integration with external objects,
161
215
  and allow easy method lookup through callback context
162
216
  * Add ability to specify custom handlers for error conditions
217
+ * Add methods synchronization for thread safety
218
+ * Add ability to define custom initial event
219
+ * Add hooks class for callbacks registration
220
+
221
+ ### Changed
222
+ * Change to ensure correct transition object state
223
+ * Extend threadable accessors
224
+
225
+ ### Fixed
226
+ * Fix bug - callback event object returns correct from state
227
+
228
+ [v0.11.1]: https://github.com/peter-murach/finite_machine/compare/v0.11.0...v0.11.1
229
+ [v0.11.0]: https://github.com/peter-murach/finite_machine/compare/v0.10.2...v0.11.0
230
+ [v0.10.2]: https://github.com/peter-murach/finite_machine/compare/v0.10.1...v0.10.2
231
+ [v0.10.1]: https://github.com/peter-murach/finite_machine/compare/v0.10.0...v0.10.1
232
+ [v0.10.0]: https://github.com/peter-murach/finite_machine/compare/v0.9.2...v0.10.0
233
+ [v0.9.2]: https://github.com/peter-murach/finite_machine/compare/v0.9.1...v0.9.2
234
+ [v0.9.1]: https://github.com/peter-murach/finite_machine/compare/v0.9.0...v0.9.1
235
+ [v0.9.0]: https://github.com/peter-murach/finite_machine/compare/v0.8.1...v0.9.0
236
+ [v0.8.1]: https://github.com/peter-murach/finite_machine/compare/v0.8.0...v0.8.1
237
+ [v0.8.0]: https://github.com/peter-murach/finite_machine/compare/v0.7.1...v0.8.0
238
+ [v0.7.1]: https://github.com/peter-murach/finite_machine/compare/v0.7.0...v0.7.1
239
+ [v0.7.0]: https://github.com/peter-murach/finite_machine/compare/v0.6.1...v0.7.0
240
+ [v0.6.1]: https://github.com/peter-murach/finite_machine/compare/v0.6.0...v0.6.1
241
+ [v0.6.0]: https://github.com/peter-murach/finite_machine/compare/v0.5.0...v0.6.0
242
+ [v0.5.0]: https://github.com/peter-murach/finite_machine/compare/v0.4.0...v0.5.0
243
+ [v0.4.0]: https://github.com/peter-murach/finite_machine/compare/v0.3.0...v0.4.0
244
+ [v0.3.0]: https://github.com/peter-murach/finite_machine/compare/v0.2.0...v0.3.0
245
+ [v0.2.0]: https://github.com/peter-murach/finite_machine/compare/v0.1.0...v0.2.0
data/Gemfile CHANGED
@@ -4,8 +4,7 @@ gemspec
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '~> 0.10.1'
7
- gem 'rake', '~> 10.4.2'
8
- gem 'rspec', '~> 3.3.0'
7
+ gem 'rspec', '~> 3.4.0'
9
8
  gem 'yard', '~> 0.8.7'
10
9
  end
11
10
 
@@ -18,5 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
22
23
  end
@@ -233,19 +233,17 @@ module FiniteMachine
233
233
  transition.to_state(from_state)
234
234
  end
235
235
 
236
- # Set cancelled status for all transitions matching event name
236
+ # Set status to cancelled for all transitions matching event name
237
237
  #
238
238
  # @param [Symbol] name
239
239
  # the event name
240
- # @param [Symbol] status
241
- # true to cancel, false otherwise
242
240
  #
243
241
  # @return [nil]
244
242
  #
245
243
  # @api public
246
- def cancel_transitions(name, status)
244
+ def cancel_transitions(name)
247
245
  chain[name].each do |trans|
248
- trans.cancelled = status
246
+ trans.cancelled = true
249
247
  end
250
248
  end
251
249
 
@@ -61,7 +61,7 @@ module FiniteMachine
61
61
  # @param [Event] event
62
62
  #
63
63
  # @example
64
- # hooks.call(:entersate, :green, Event.new)
64
+ # hooks.call(HookEvent::Enter, :green, Event.new)
65
65
  #
66
66
  # @return [Hash]
67
67
  #
@@ -79,6 +79,13 @@ module FiniteMachine
79
79
  collection.empty?
80
80
  end
81
81
 
82
+ # Remove all callbacks
83
+ #
84
+ # @api public
85
+ def clear
86
+ collection.clear
87
+ end
88
+
82
89
  # String representation
83
90
  #
84
91
  # @return [String]
@@ -170,8 +170,10 @@ module FiniteMachine
170
170
  result = callable.call(trans_event, *data)
171
171
  end
172
172
 
173
- machine.events_chain.cancel_transitions(event.event_name,
174
- (result == CANCELLED))
173
+ if result == CANCELLED
174
+ hooks.clear
175
+ machine.events_chain.cancel_transitions(event.event_name)
176
+ end
175
177
  end
176
178
 
177
179
  # Callback names including all states and events
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module FiniteMachine
4
- VERSION = "0.11.0"
4
+ VERSION = "0.11.1"
5
5
  end
@@ -708,6 +708,34 @@ RSpec.describe FiniteMachine, 'callbacks' do
708
708
  expect(fsm.current).to eql(:green)
709
709
  end
710
710
 
711
+ it "stops executing callbacks when cancelled" do
712
+ called = []
713
+
714
+ fsm = FiniteMachine.define do
715
+ initial :initial
716
+
717
+ events { event :bump, initial: :low }
718
+
719
+ callbacks {
720
+ on_before do |event|
721
+ called << "enter_#{event.name}_#{event.from}_#{event.to}"
722
+
723
+ FiniteMachine::CANCELLED
724
+ end
725
+
726
+ on_exit :initial do |event| called << "exit_initial" end
727
+ on_exit do |event| called << "exit_any" end
728
+ on_enter :low do |event| called << "enter_low" end
729
+ on_after :bump do |event| called << "after_#{event.name}" end
730
+ on_after do |event| called << "after_any" end
731
+ }
732
+ end
733
+
734
+ fsm.bump
735
+
736
+ expect(called).to eq(['enter_bump_initial_low'])
737
+ end
738
+
711
739
  xit "groups callbacks"
712
740
 
713
741
  it "groups states from separate events with the same name" do
@@ -13,7 +13,7 @@ RSpec.describe FiniteMachine::EventsChain, '.cancel_transitions' do
13
13
  events_chain.add(:start, transition_b)
14
14
  events_chain.add(:finish, transition_c)
15
15
 
16
- events_chain.cancel_transitions(:start, true)
16
+ events_chain.cancel_transitions(:start)
17
17
 
18
18
  expect(transition_a).to have_received(:cancelled=).with(true)
19
19
  expect(transition_b).to have_received(:cancelled=).with(true)
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe FiniteMachine::Hooks, '#clear' do
4
+ it "clears all registered hooks" do
5
+ hooks = described_class.new
6
+
7
+ event_type = FiniteMachine::HookEvent::Before
8
+ hook = -> { }
9
+ hooks.register(event_type, :foo, hook)
10
+ hooks.register(event_type, :bar, hook)
11
+
12
+ expect(hooks.empty?).to eq(false)
13
+ hooks.clear
14
+ expect(hooks.empty?).to eq(true)
15
+ end
16
+ end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finite_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-11 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: A minimal finite state machine with a straightforward syntax. You can
28
42
  quickly model states, add callbacks and use object-oriented techniques to integrate
29
43
  with ORMs.
@@ -104,6 +118,7 @@ files:
104
118
  - spec/unit/hook_event/initialize_spec.rb
105
119
  - spec/unit/hook_event/notify_spec.rb
106
120
  - spec/unit/hooks/call_spec.rb
121
+ - spec/unit/hooks/clear_spec.rb
107
122
  - spec/unit/hooks/inspect_spec.rb
108
123
  - spec/unit/hooks/register_spec.rb
109
124
  - spec/unit/if_unless_spec.rb
@@ -181,6 +196,7 @@ test_files:
181
196
  - spec/unit/hook_event/initialize_spec.rb
182
197
  - spec/unit/hook_event/notify_spec.rb
183
198
  - spec/unit/hooks/call_spec.rb
199
+ - spec/unit/hooks/clear_spec.rb
184
200
  - spec/unit/hooks/inspect_spec.rb
185
201
  - spec/unit/hooks/register_spec.rb
186
202
  - spec/unit/if_unless_spec.rb