stateflow 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -13,3 +13,4 @@ lib/stateflow/persistence/active_record.rb
13
13
  lib/stateflow/persistence/mongo_mapper.rb
14
14
  lib/stateflow/state.rb
15
15
  lib/stateflow/transition.rb
16
+ stateflow.gemspec
data/README.rdoc CHANGED
@@ -2,10 +2,98 @@
2
2
 
3
3
  == TODO
4
4
 
5
- * Persistence layers
5
+ * More Persistence layers
6
6
  * Tests
7
7
 
8
- This is the basics of the gem. THIS IS NOT PRODUCTION READY UNTIL TESTS ARE DONE. Please check out the examples directory for usage until this readme gets fleshed out. Feel free to fork and modify as you please.
8
+ This is the basics of the gem. THIS IS NOT PRODUCTION READY UNTIL TESTS ARE DONE. Please check out the examples directory for usage until this README gets fleshed out. Feel free to fork and modify as you please.
9
+
10
+ == Usage
11
+
12
+ Stateflow supports persistence with MongoMapper, and ActiveRecord. Adding more is really basic, please request any if needed.
13
+
14
+ Stateflow defaults to ActiveRecord but you can set the persistence layer with:
15
+
16
+ Stateflow.persistence = :mongo_mapper
17
+ OR
18
+ Stateflow.persistence = :active_record
19
+
20
+ == Basic Example
21
+
22
+ require 'rubygems'
23
+ require 'stateflow'
24
+
25
+ class Robot
26
+ include Stateflow
27
+
28
+ stateflow do
29
+ initial :green
30
+
31
+ state :green, :yellow, :red
32
+
33
+ event :change_color do
34
+ transitions :from => :green, :to => :yellow
35
+ transitions :from => :yellow, :to => :red
36
+ transitions :from => :red, :to => :green
37
+ end
38
+ end
39
+ end
40
+
41
+ == Advanced Example
42
+
43
+ require 'rubygems'
44
+ require 'stateflow'
45
+
46
+ class Test
47
+ include Stateflow
48
+
49
+ stateflow do
50
+
51
+ initial :love
52
+
53
+ state :love do
54
+ enter lambda { |t| p "Entering love" }
55
+ exit :exit_love
56
+ end
57
+
58
+ state :hate do
59
+ enter lambda { |t| p "Entering hate" }
60
+ exit lambda { |t| p "Exiting hate" }
61
+ end
62
+
63
+ state :mixed do
64
+ enter lambda { |t| p "Entering mixed" }
65
+ exit lambda { |t| p "Exiting mixed" }
66
+ end
67
+
68
+ event :b do
69
+ transitions :from => :love, :to => :hate, :if => :no_ice_cream
70
+ transitions :from => :hate, :to => :love
71
+ end
72
+
73
+ event :a do
74
+ transitions :from => :love, :to => [:hate, :mixed], :decide => :likes_ice_cream?
75
+ transitions :from => [:hate, :mixed], :to => :love
76
+ end
77
+ end
78
+
79
+ def likes_ice_cream?
80
+ rand(10) > 5 ? :mixeds : :hate
81
+ end
82
+
83
+ def exit_love
84
+ p "Exiting love"
85
+ end
86
+
87
+ def no_ice_cream
88
+ rand(4) > 2 ? true : false
89
+ end
90
+ end
91
+
92
+ As you can see Stateflow allows dynamic :to transitions. *This allows your flows to be dynamic, and is the main feature of this gem over the others.*
93
+
94
+ You can set the default column with the state_column function in the stateflow block. The default state column is ":state".
95
+
96
+ state_column :state
9
97
 
10
98
  == Note on Patches/Pull Requests
11
99
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('stateflow', '0.0.2') do |p|
5
+ Echoe.new('stateflow', '0.0.3') 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"
@@ -2,7 +2,7 @@ module Stateflow
2
2
  module Persistence
3
3
  module MongoMapper
4
4
  def self.install(base)
5
- base.send :key, :state, String
5
+ base.send :key, self.machine.state_column.to_sym, String
6
6
  base.before_validation_on_create :ensure_initial_state
7
7
  base.send :include, InstanceMethods
8
8
  end
data/stateflow.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{stateflow}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stateflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Oberholzer