stateflow 0.1.2 → 0.2.0

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/CHANGELOG.rdoc CHANGED
@@ -1,2 +1,6 @@
1
+ = Version 0.2
2
+ * Added a transition to any event, please look at the tests to understand how it works - Thanks to nu7hatch for the patch!
3
+ * Changed the persistence layers to use write_attribute, instead of update_attribute - Thanks to achirkunov
4
+
1
5
  = Version 0.1.2
2
6
  * Fixed Mongoid support - Thanks bmartin for pointing that out
data/Manifest CHANGED
@@ -1,5 +1,6 @@
1
1
  CHANGELOG.rdoc
2
2
  LICENCE
3
+ Manifest
3
4
  README.rdoc
4
5
  Rakefile
5
6
  examples/robot.rb
@@ -19,4 +20,3 @@ lib/stateflow/transition.rb
19
20
  spec/spec_helper.rb
20
21
  spec/stateflow_spec.rb
21
22
  stateflow.gemspec
22
- Manifest
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('stateflow', '0.1.2') do |p|
5
+ Echoe.new('stateflow', '0.2.0') 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"
@@ -1,9 +1,10 @@
1
1
  module Stateflow
2
2
  class Event
3
- attr_accessor :name, :transitions
3
+ attr_accessor :name, :transitions, :machine
4
4
 
5
- def initialize(name, &transitions)
5
+ def initialize(name, machine=nil, &transitions)
6
6
  @name = name
7
+ @machine = machine
7
8
  @transitions = Array.new
8
9
 
9
10
  instance_eval(&transitions)
@@ -29,5 +30,9 @@ module Stateflow
29
30
  transition = Stateflow::Transition.new(args)
30
31
  @transitions << transition
31
32
  end
33
+
34
+ def any
35
+ @machine.states.keys
36
+ end
32
37
  end
33
- end
38
+ end
@@ -25,8 +25,8 @@ module Stateflow
25
25
  end
26
26
 
27
27
  def event(name, &transitions)
28
- event = Stateflow::Event.new(name, &transitions)
28
+ event = Stateflow::Event.new(name, self, &transitions)
29
29
  @events[name.to_sym] = event
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -12,7 +12,8 @@ module Stateflow
12
12
  end
13
13
 
14
14
  def save_to_persistence(new_state)
15
- self.update_attribute(machine.state_column.to_sym, new_state)
15
+ self.write_attribute(machine.state_column.to_sym, new_state)
16
+ self.save
16
17
  end
17
18
 
18
19
  def ensure_initial_state
@@ -12,7 +12,8 @@ module Stateflow
12
12
  end
13
13
 
14
14
  def save_to_persistence(new_state)
15
- self.update_attributes(machine.state_column.to_sym => new_state)
15
+ self.write_attribute(machine.state_column.to_sym, new_state)
16
+ self.save
16
17
  end
17
18
 
18
19
  def ensure_initial_state
@@ -12,7 +12,8 @@ module Stateflow
12
12
  end
13
13
 
14
14
  def save_to_persistence(new_state)
15
- self.update_attributes(machine.state_column.to_sym => new_state)
15
+ self.write_attribute(machine.state_column.to_sym, new_state)
16
+ self.save
16
17
  end
17
18
 
18
19
  def ensure_initial_state
@@ -89,6 +89,27 @@ class Dater
89
89
  end
90
90
  end
91
91
 
92
+ class Priority
93
+ include Stateflow
94
+
95
+ stateflow do
96
+ initial :medium
97
+ state :low, :medium, :high
98
+
99
+ event :low do
100
+ transitions :from => any, :to => :low
101
+ end
102
+
103
+ event :medium do
104
+ transitions :from => any, :to => :medium
105
+ end
106
+
107
+ event :high do
108
+ transitions :from => any, :to => :high
109
+ end
110
+ end
111
+ end
112
+
92
113
  describe Stateflow do
93
114
  describe "class methods" do
94
115
  it "should respond to stateflow block to setup the intial stateflow" do
@@ -273,5 +294,17 @@ describe Stateflow do
273
294
  date.current_state.name.should == :single
274
295
  end
275
296
  end
297
+
298
+ describe "transitions from any" do
299
+ it "should properly change state" do
300
+ priority = Priority.new
301
+ priority.low!
302
+ priority.should be_low
303
+ priority.medium!
304
+ priority.should be_medium
305
+ priority.high!
306
+ priority.should be_high
307
+ end
308
+ end
276
309
  end
277
310
 
data/stateflow.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{stateflow}
5
- s.version = "0.1.2"
5
+ s.version = "0.2.0"
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-08-31}
9
+ s.date = %q{2010-09-22}
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"]
13
- s.files = ["CHANGELOG.rdoc", "LICENCE", "README.rdoc", "Rakefile", "examples/robot.rb", "examples/test.rb", "init.rb", "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", "spec/spec_helper.rb", "spec/stateflow_spec.rb", "stateflow.gemspec", "Manifest"]
13
+ s.files = ["CHANGELOG.rdoc", "LICENCE", "Manifest", "README.rdoc", "Rakefile", "examples/robot.rb", "examples/test.rb", "init.rb", "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", "spec/spec_helper.rb", "spec/stateflow_spec.rb", "stateflow.gemspec"]
14
14
  s.homepage = %q{http://github.com/ryanza/stateflow}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Stateflow", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
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: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
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-08-31 00:00:00 +02:00
18
+ date: 2010-09-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ extra_rdoc_files:
55
55
  files:
56
56
  - CHANGELOG.rdoc
57
57
  - LICENCE
58
+ - Manifest
58
59
  - README.rdoc
59
60
  - Rakefile
60
61
  - examples/robot.rb
@@ -74,7 +75,6 @@ files:
74
75
  - spec/spec_helper.rb
75
76
  - spec/stateflow_spec.rb
76
77
  - stateflow.gemspec
77
- - Manifest
78
78
  has_rdoc: true
79
79
  homepage: http://github.com/ryanza/stateflow
80
80
  licenses: []