statemachine 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,11 @@
1
1
  = Statemachine Changelog
2
2
 
3
+ == Version 2.3.0
4
+
5
+ * Introduce on_state_change for building persistent states from @godfat (https://github.com/slagyr/statemachine/pull/13)
6
+ * Update rake tasks according to it's deprecation messages from @godfat (https://github.com/slagyr/statemachine/pull/14)
7
+ * Base Exceptions on StandardError from @Asmod4n (https://github.com/slagyr/statemachine/pull/15)
8
+
3
9
  == Version 2.2.0
4
10
 
5
11
  * applied dotfile improvements from @wsobel (https://github.com/slagyr/statemachine/pull/12)
@@ -17,11 +17,11 @@ Some documentation is available here in this RDOC documentation.
17
17
  You may also find useful documentation on the Statemachine website: http://slagyr.github.com/statemachine
18
18
 
19
19
  A detailed tutorial and overview of Finite State Machines and this library can be found
20
- at http://blog.8thlight.com/articles/2006/11/17/understanding-statemachines-part-1-states-and-transitions.
20
+ at http://blog.8thlight.com/micah-martin/2006/11/17/understanding-statemachines-part-1-states-and-transitions.html
21
21
 
22
22
  == License
23
23
 
24
- Copyright (C) 2006-2010 Micah Martin
24
+ Copyright (C) 2006-2014 Micah Martin
25
25
 
26
26
  This library is free software; you can redistribute it and/or
27
27
  modify it under the terms of the GNU Lesser General Public
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  $:.unshift('lib')
2
2
  require 'rubygems'
3
- require 'rake/gempackagetask'
3
+ require 'rubygems/package_task'
4
4
  require 'rake/clean'
5
- require 'rake/rdoctask'
5
+ require 'rdoc/task'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'statemachine'
8
8
  require "bundler/gem_tasks"
@@ -85,4 +85,4 @@ end
85
85
 
86
86
  task :verify_password do
87
87
  raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
88
- end
88
+ end
@@ -276,6 +276,13 @@ module Statemachine
276
276
  require 'statemachine/stub_context'
277
277
  context StubContext.new(options)
278
278
  end
279
+
280
+ # This callback would be called whenever the statemachine is changing the state.
281
+ # This is useful whenever we want to make the state persistent and store into
282
+ # some database.
283
+ def on_state_change(action=nil, &block)
284
+ @statemachine.state_change_action = action || block
285
+ end
279
286
  end
280
287
 
281
288
  end
@@ -1,9 +1,9 @@
1
1
  module Statemachine
2
2
 
3
- class StatemachineException < Exception
3
+ class StatemachineException < StandardError
4
4
  end
5
5
 
6
- class TransitionMissingException < Exception
6
+ class TransitionMissingException < StandardError
7
7
  end
8
8
 
9
9
  # Used at runtime to execute the behavior of the statemachine.
@@ -38,6 +38,11 @@ module Statemachine
38
38
  # so that they can be matched to the correct statemachine.
39
39
  attr_accessor :name
40
40
 
41
+ # This callback would be called whenever the statemachine is changing the state.
42
+ # This is useful whenever we want to make the state persistent and store into
43
+ # some database.
44
+ attr_accessor :state_change_action
45
+
41
46
  attr_reader :root #:nodoc:
42
47
 
43
48
  # Should not be called directly. Instances of Statemachine::Statemachine are created
@@ -55,9 +60,9 @@ module Statemachine
55
60
 
56
61
  # Resets the statemachine back to its starting state.
57
62
  def reset
58
- @state = get_state(@root.startstate_id)
63
+ self.state = get_state(@root.startstate_id)
59
64
  while @state and not @state.concrete?
60
- @state = get_state(@state.startstate_id)
65
+ self.state = get_state(@state.startstate_id)
61
66
  end
62
67
  raise StatemachineException.new("The state machine doesn't know where to start. Try setting the startstate.") if @state == nil
63
68
  @state.enter
@@ -80,6 +85,8 @@ module Statemachine
80
85
  elsif value and @states[value.to_sym]
81
86
  @state = @states[value.to_sym]
82
87
  end
88
+
89
+ invoke_action(state_change_action, [@state], "state change action to #{@state}") if state_change_action
83
90
  end
84
91
 
85
92
  # The key method to exercise the statemachine. Any extra arguments supplied will be passed into
@@ -2,7 +2,7 @@ module Statemachine
2
2
  module VERSION #:nodoc:
3
3
  unless defined? MAJOR
4
4
  MAJOR = 2
5
- MINOR = 2
5
+ MINOR = 3
6
6
  TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
+
3
+ describe "State Machine State Change Action" do
4
+
5
+ before(:each) do
6
+ me = self
7
+ @sm = Statemachine.build do
8
+ trans :default_state, :start, :test_state
9
+
10
+ context me
11
+
12
+ sm = statemachine
13
+ on_state_change do
14
+ @state = sm.state
15
+ end
16
+ end
17
+ end
18
+
19
+ it "would call on_state_change when the state was changed" do
20
+ @state.should eql(:default_state)
21
+ @sm.start
22
+ @state.should eql(:test_state)
23
+ end
24
+ end
25
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statemachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire: statemachine
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
12
+ date: 2014-08-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Statemachine is a ruby library for building Finite State Machines (FSM),
15
15
  also known as Finite State Automata (FSA).
@@ -177,6 +177,7 @@ files:
177
177
  - spec/sm_entry_exit_actions_spec.rb
178
178
  - spec/sm_odds_n_ends_spec.rb
179
179
  - spec/sm_simple_spec.rb
180
+ - spec/sm_state_change_action_spec.rb
180
181
  - spec/sm_super_state_spec.rb
181
182
  - spec/sm_turnstile_spec.rb
182
183
  - spec/spec_helper.rb
@@ -205,7 +206,7 @@ rubyforge_project: statemachine
205
206
  rubygems_version: 1.8.24
206
207
  signing_key:
207
208
  specification_version: 3
208
- summary: Statemachine-2.2.0 - Statemachine Library for Ruby http://slagyr.github.com/statemachine
209
+ summary: Statemachine-2.3.0 - Statemachine Library for Ruby http://slagyr.github.com/statemachine
209
210
  test_files:
210
211
  - spec/action_invokation_spec.rb
211
212
  - spec/builder_spec.rb
@@ -217,6 +218,7 @@ test_files:
217
218
  - spec/sm_entry_exit_actions_spec.rb
218
219
  - spec/sm_odds_n_ends_spec.rb
219
220
  - spec/sm_simple_spec.rb
221
+ - spec/sm_state_change_action_spec.rb
220
222
  - spec/sm_super_state_spec.rb
221
223
  - spec/sm_turnstile_spec.rb
222
224
  - spec/spec_helper.rb