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 +4 -0
- data/Manifest +1 -1
- data/Rakefile +1 -1
- data/lib/stateflow/event.rb +8 -3
- data/lib/stateflow/machine.rb +2 -2
- data/lib/stateflow/persistence/active_record.rb +2 -1
- data/lib/stateflow/persistence/mongo_mapper.rb +2 -1
- data/lib/stateflow/persistence/mongoid.rb +2 -1
- data/spec/stateflow_spec.rb +33 -0
- data/stateflow.gemspec +3 -3
- metadata +5 -5
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
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('stateflow', '0.
|
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"
|
data/lib/stateflow/event.rb
CHANGED
@@ -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
|
data/lib/stateflow/machine.rb
CHANGED
data/spec/stateflow_spec.rb
CHANGED
@@ -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.
|
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-
|
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"
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
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-
|
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: []
|