stateflow 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ = Version 0.2.2
2
+ * Previous state can be accessed with `_previous_state` instance method after transitioning states
3
+
1
4
  = Version 0.2.1
2
5
  * Reverted the writes back to update_attributes
3
6
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('stateflow', '0.2.1') do |p|
5
+ Echoe.new('stateflow', '0.2.2') do |p|
6
6
  p.description = "State machine that allows dynamic transitions for business workflows"
7
7
  p.url = "http://github.com/ryanza/stateflow"
8
8
  p.author = "Ryan Oberholzer"
@@ -21,6 +21,8 @@ module Stateflow
21
21
 
22
22
  current_state.execute_action(:exit, klass)
23
23
  klass.current_state = new_state
24
+
25
+ klass._previous_state = current_state.name.to_s
24
26
  new_state.execute_action(:enter, klass)
25
27
  true
26
28
  end
@@ -11,7 +11,7 @@ module Stateflow
11
11
  @state_column ||= name.nil? ? :state : name
12
12
  end
13
13
 
14
- private
14
+ private
15
15
  def initial(name)
16
16
  @initial_state_name = name
17
17
  end
data/lib/stateflow.rb CHANGED
@@ -35,6 +35,8 @@ module Stateflow
35
35
  end
36
36
 
37
37
  module InstanceMethods
38
+ attr_accessor :_previous_state
39
+
38
40
  def current_state
39
41
  @current_state ||= load_from_persistence.nil? ? machine.initial_state : machine.states[load_from_persistence.to_sym]
40
42
  end
@@ -110,6 +110,21 @@ class Priority
110
110
  end
111
111
  end
112
112
 
113
+ class Stater
114
+ include Stateflow
115
+
116
+ stateflow do
117
+ initial :bill
118
+
119
+ state :bob, :bill
120
+
121
+ event :lolcats do
122
+ transitions :from => :bill, :to => :bob
123
+ end
124
+ end
125
+ end
126
+
127
+
113
128
  describe Stateflow do
114
129
  describe "class methods" do
115
130
  it "should respond to stateflow block to setup the intial stateflow" do
@@ -306,5 +321,15 @@ describe Stateflow do
306
321
  priority.should be_high
307
322
  end
308
323
  end
324
+
325
+ describe "previous state" do
326
+ it "should display the previous state" do
327
+ stater = Stater.new
328
+ stater.lolcats!
329
+
330
+ stater._previous_state.should == "bill"
331
+ stater.current_state == "bob"
332
+ end
333
+ end
309
334
  end
310
335
 
data/stateflow.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{stateflow}
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan Oberholzer"]
9
- s.date = %q{2010-10-01}
9
+ s.date = %q{2010-10-19}
10
10
  s.description = %q{State machine that allows dynamic transitions for business workflows}
11
11
  s.email = %q{ryan@platform45.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/stateflow.rb", "lib/stateflow/event.rb", "lib/stateflow/exception.rb", "lib/stateflow/machine.rb", "lib/stateflow/persistence.rb", "lib/stateflow/persistence/active_record.rb", "lib/stateflow/persistence/mongo_mapper.rb", "lib/stateflow/persistence/mongoid.rb", "lib/stateflow/persistence/none.rb", "lib/stateflow/state.rb", "lib/stateflow/transition.rb"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stateflow
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Oberholzer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-01 00:00:00 +02:00
18
+ date: 2010-10-19 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency