simple_state_machine 0.5.0.beta → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -14
- data/lib/simple_state_machine/rails2_task_loader.rb +2 -0
- data/lib/simple_state_machine/railtie.rb +11 -0
- data/lib/simple_state_machine/version.rb +1 -1
- data/lib/simple_state_machine.rb +2 -0
- data/lib/tasks/graphiz.rake +13 -0
- data/rails/graphiz.rake +16 -0
- data/simple_state_machine.gemspec +2 -2
- metadata +16 -16
- data/Gemfile.lock +0 -34
data/README.rdoc
CHANGED
@@ -53,26 +53,33 @@ To add a state machine:
|
|
53
53
|
- turn methods into events
|
54
54
|
|
55
55
|
class LampWithHotelSwitch
|
56
|
-
|
56
|
+
|
57
57
|
extend SimpleStateMachine
|
58
|
-
|
58
|
+
|
59
59
|
def initialize
|
60
|
-
self.state =
|
60
|
+
self.state = 'off'
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def push_switch_1
|
64
|
-
puts
|
64
|
+
puts "pushed switch 1 #{state}"
|
65
65
|
end
|
66
66
|
event :push_switch_1, :off => :on,
|
67
67
|
:on => :off
|
68
|
-
|
68
|
+
|
69
69
|
# define another event
|
70
70
|
# note that implementation of :push_switch_2 is optional
|
71
71
|
event :push_switch_2, :off => :on,
|
72
72
|
:on => :off
|
73
|
-
|
73
|
+
|
74
74
|
end
|
75
75
|
|
76
|
+
lamp = LampWithHotelSwitch.new
|
77
|
+
lamp.state # => 'off'
|
78
|
+
lamp.push_switch_1
|
79
|
+
lamp.state # => 'on'
|
80
|
+
lamp.push_siwtch_2
|
81
|
+
lamp.state # => 'off'
|
82
|
+
|
76
83
|
== ActiveRecord Example
|
77
84
|
|
78
85
|
To add a state machine with ActiveRecord persistence:
|
@@ -83,8 +90,6 @@ To add a state machine with ActiveRecord persistence:
|
|
83
90
|
class User < ActiveRecord::Base
|
84
91
|
|
85
92
|
extend SimpleStateMachine::ActiveRecord
|
86
|
-
# define a custum state_method (state is default)
|
87
|
-
state_machine_definition.state_method = :ssm_state
|
88
93
|
|
89
94
|
def after_initialize
|
90
95
|
self.ssm_state ||= 'new'
|
@@ -110,11 +115,18 @@ To add a state machine with ActiveRecord persistence:
|
|
110
115
|
event :suspend, :all => :suspended
|
111
116
|
end
|
112
117
|
|
113
|
-
This generates the following methods
|
114
|
-
-
|
115
|
-
-
|
116
|
-
-
|
117
|
-
|
118
|
+
This generates the following event methods
|
119
|
+
- invite!
|
120
|
+
- confirm_invitation!
|
121
|
+
- suspend!
|
122
|
+
And the following methods to query the state:
|
123
|
+
- invited?
|
124
|
+
- active?
|
125
|
+
- suspended?
|
126
|
+
|
127
|
+
If you want to be more verbose you can also use:
|
128
|
+
- invite_and_save (behave like ActiveRecord save)
|
129
|
+
- invite_and_save! (is equal to invite! and behaves like save!)
|
118
130
|
|
119
131
|
|
120
132
|
This code was just released, we do not claim it to be stable.
|
data/lib/simple_state_machine.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :ssm do
|
2
|
+
namespace :graph do
|
3
|
+
desc 'Generate a url for a google chart for [class]'
|
4
|
+
task :url => :environment do
|
5
|
+
puts ENV['class'].constantize.state_machine_definition.google_chart_url
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Opens the google chart in the browser for [class]'
|
9
|
+
task :open => :environment do
|
10
|
+
`open '#{::CGI.unescape(ENV['class'].constantize.state_machine_definition.google_chart_url)}'`
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/rails/graphiz.rake
ADDED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
|
10
10
|
s.authors = ["Marek de Heus", "Petrik de Heus"]
|
11
|
-
s.description = %q{
|
11
|
+
s.description = %q{Simple State Machine is a state machine that focuses on events instead of states}
|
12
12
|
s.email = ["FIX@example.com"]
|
13
13
|
s.homepage = %q{http://github.com/mdh/ssm}
|
14
14
|
s.extra_rdoc_files = [
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.rdoc_options = ["--charset=UTF-8"]
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
s.rubygems_version = %q{1.3.7}
|
23
|
-
s.summary = %q{A
|
23
|
+
s.summary = %q{A simple DSL to decorate existing methods with logic that guards state transitions.}
|
24
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
25
|
s.add_development_dependency "rake"
|
26
26
|
s.add_development_dependency "ZenTest"
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_state_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.5.0.beta
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Marek de Heus
|
@@ -17,7 +16,7 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date: 2011-
|
19
|
+
date: 2011-03-06 00:00:00 +01:00
|
21
20
|
default_executable:
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
@@ -92,7 +91,7 @@ dependencies:
|
|
92
91
|
version: "0"
|
93
92
|
type: :development
|
94
93
|
version_requirements: *id005
|
95
|
-
description:
|
94
|
+
description: Simple State Machine is a state machine that focuses on events instead of states
|
96
95
|
email:
|
97
96
|
- FIX@example.com
|
98
97
|
executables: []
|
@@ -106,7 +105,6 @@ files:
|
|
106
105
|
- .gitignore
|
107
106
|
- .rspec
|
108
107
|
- Gemfile
|
109
|
-
- Gemfile.lock
|
110
108
|
- LICENSE
|
111
109
|
- README.rdoc
|
112
110
|
- Rakefile
|
@@ -118,8 +116,12 @@ files:
|
|
118
116
|
- examples/user.rb
|
119
117
|
- lib/simple_state_machine.rb
|
120
118
|
- lib/simple_state_machine/active_record.rb
|
119
|
+
- lib/simple_state_machine/rails2_task_loader.rb
|
120
|
+
- lib/simple_state_machine/railtie.rb
|
121
121
|
- lib/simple_state_machine/simple_state_machine.rb
|
122
122
|
- lib/simple_state_machine/version.rb
|
123
|
+
- lib/tasks/graphiz.rake
|
124
|
+
- rails/graphiz.rake
|
123
125
|
- simple_state_machine.gemspec
|
124
126
|
- spec/active_record_spec.rb
|
125
127
|
- spec/decorator_spec.rb
|
@@ -150,21 +152,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
153
|
none: false
|
152
154
|
requirements:
|
153
|
-
- - "
|
155
|
+
- - ">="
|
154
156
|
- !ruby/object:Gem::Version
|
155
|
-
hash:
|
157
|
+
hash: 3
|
156
158
|
segments:
|
157
|
-
-
|
158
|
-
|
159
|
-
- 1
|
160
|
-
version: 1.3.1
|
159
|
+
- 0
|
160
|
+
version: "0"
|
161
161
|
requirements: []
|
162
162
|
|
163
163
|
rubyforge_project:
|
164
|
-
rubygems_version: 1.5.
|
164
|
+
rubygems_version: 1.5.2
|
165
165
|
signing_key:
|
166
166
|
specification_version: 3
|
167
|
-
summary: A
|
167
|
+
summary: A simple DSL to decorate existing methods with logic that guards state transitions.
|
168
168
|
test_files:
|
169
169
|
- spec/active_record_spec.rb
|
170
170
|
- spec/decorator_spec.rb
|
data/Gemfile.lock
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
simple_state_machine (1.5.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ZenTest (4.4.2)
|
10
|
-
activerecord (2.3.10)
|
11
|
-
activesupport (= 2.3.10)
|
12
|
-
activesupport (2.3.10)
|
13
|
-
diff-lcs (1.1.2)
|
14
|
-
rake (0.8.7)
|
15
|
-
rspec (2.5.0)
|
16
|
-
rspec-core (~> 2.5.0)
|
17
|
-
rspec-expectations (~> 2.5.0)
|
18
|
-
rspec-mocks (~> 2.5.0)
|
19
|
-
rspec-core (2.5.1)
|
20
|
-
rspec-expectations (2.5.0)
|
21
|
-
diff-lcs (~> 1.1.2)
|
22
|
-
rspec-mocks (2.5.0)
|
23
|
-
sqlite3-ruby (1.3.1)
|
24
|
-
|
25
|
-
PLATFORMS
|
26
|
-
ruby
|
27
|
-
|
28
|
-
DEPENDENCIES
|
29
|
-
ZenTest
|
30
|
-
activerecord (~> 2.3.5)
|
31
|
-
rake
|
32
|
-
rspec
|
33
|
-
simple_state_machine!
|
34
|
-
sqlite3-ruby
|