simple_state_machine 0.5.3 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog.rdoc +23 -0
- data/README.rdoc +154 -100
- data/lib/simple_state_machine/active_record.rb +2 -62
- data/lib/simple_state_machine/decorator/active_record.rb +68 -0
- data/lib/simple_state_machine/decorator/default.rb +91 -0
- data/lib/simple_state_machine/railtie.rb +1 -1
- data/lib/simple_state_machine/simple_state_machine.rb +8 -251
- data/lib/simple_state_machine/state_machine.rb +88 -0
- data/lib/simple_state_machine/state_machine_definition.rb +72 -0
- data/lib/simple_state_machine/tools/graphviz.rb +21 -0
- data/lib/simple_state_machine/tools/inspector.rb +44 -0
- data/lib/simple_state_machine/transition.rb +40 -0
- data/lib/simple_state_machine/version.rb +1 -1
- data/lib/simple_state_machine.rb +13 -3
- data/lib/tasks/graphviz.rake +31 -0
- metadata +37 -150
- data/.gitignore +0 -1
- data/.rspec +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -28
- data/autotest/discover.rb +0 -1
- data/examples/conversation.rb +0 -33
- data/examples/lamp.rb +0 -21
- data/examples/relationship.rb +0 -87
- data/examples/traffic_light.rb +0 -17
- data/examples/user.rb +0 -37
- data/lib/tasks/graphiz.rake +0 -13
- data/rails/graphiz.rake +0 -16
- data/simple_state_machine.gemspec +0 -31
- data/spec/active_record_spec.rb +0 -223
- data/spec/decorator_spec.rb +0 -195
- data/spec/examples_spec.rb +0 -60
- data/spec/mountable_spec.rb +0 -24
- data/spec/simple_state_machine_spec.rb +0 -129
- data/spec/spec_helper.rb +0 -7
- data/spec/state_machine_definition_spec.rb +0 -89
- data/spec/state_machine_spec.rb +0 -26
metadata
CHANGED
@@ -1,176 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_state_machine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 3
|
10
|
-
version: 0.5.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Marek de Heus
|
14
8
|
- Petrik de Heus
|
15
|
-
autorequire:
|
9
|
+
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Dependency
|
23
|
-
name: rake
|
24
|
-
prerelease: false
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 3
|
31
|
-
segments:
|
32
|
-
- 0
|
33
|
-
version: "0"
|
34
|
-
type: :development
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: ZenTest
|
38
|
-
prerelease: false
|
39
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
|
-
requirements:
|
42
|
-
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 3
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
version: "0"
|
48
|
-
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: rspec
|
52
|
-
prerelease: false
|
53
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
|
-
requirements:
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
version: "0"
|
62
|
-
type: :development
|
63
|
-
version_requirements: *id003
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: activerecord
|
66
|
-
prerelease: false
|
67
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
|
-
requirements:
|
70
|
-
- - ~>
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
hash: 9
|
73
|
-
segments:
|
74
|
-
- 2
|
75
|
-
- 3
|
76
|
-
- 5
|
77
|
-
version: 2.3.5
|
78
|
-
type: :development
|
79
|
-
version_requirements: *id004
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: sqlite3-ruby
|
82
|
-
prerelease: false
|
83
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
hash: 3
|
89
|
-
segments:
|
90
|
-
- 0
|
91
|
-
version: "0"
|
92
|
-
type: :development
|
93
|
-
version_requirements: *id005
|
94
|
-
description: Simple State Machine is a state machine that focuses on events instead of states
|
95
|
-
email:
|
12
|
+
date: 2021-12-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple DSL to decorate existing methods with state transition guards.
|
15
|
+
email:
|
96
16
|
- FIX@example.com
|
97
17
|
executables: []
|
98
|
-
|
99
18
|
extensions: []
|
100
|
-
|
101
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
102
20
|
- LICENSE
|
103
21
|
- README.rdoc
|
104
|
-
files:
|
105
|
-
- .
|
106
|
-
- .rspec
|
107
|
-
- Gemfile
|
22
|
+
files:
|
23
|
+
- Changelog.rdoc
|
108
24
|
- LICENSE
|
109
25
|
- README.rdoc
|
110
|
-
- Rakefile
|
111
|
-
- autotest/discover.rb
|
112
|
-
- examples/conversation.rb
|
113
|
-
- examples/lamp.rb
|
114
|
-
- examples/relationship.rb
|
115
|
-
- examples/traffic_light.rb
|
116
|
-
- examples/user.rb
|
117
26
|
- lib/simple_state_machine.rb
|
118
27
|
- lib/simple_state_machine/active_record.rb
|
28
|
+
- lib/simple_state_machine/decorator/active_record.rb
|
29
|
+
- lib/simple_state_machine/decorator/default.rb
|
119
30
|
- lib/simple_state_machine/rails2_task_loader.rb
|
120
31
|
- lib/simple_state_machine/railtie.rb
|
121
32
|
- lib/simple_state_machine/simple_state_machine.rb
|
33
|
+
- lib/simple_state_machine/state_machine.rb
|
34
|
+
- lib/simple_state_machine/state_machine_definition.rb
|
35
|
+
- lib/simple_state_machine/tools/graphviz.rb
|
36
|
+
- lib/simple_state_machine/tools/inspector.rb
|
37
|
+
- lib/simple_state_machine/transition.rb
|
122
38
|
- lib/simple_state_machine/version.rb
|
123
|
-
- lib/tasks/
|
124
|
-
- rails/graphiz.rake
|
125
|
-
- simple_state_machine.gemspec
|
126
|
-
- spec/active_record_spec.rb
|
127
|
-
- spec/decorator_spec.rb
|
128
|
-
- spec/examples_spec.rb
|
129
|
-
- spec/mountable_spec.rb
|
130
|
-
- spec/simple_state_machine_spec.rb
|
131
|
-
- spec/spec_helper.rb
|
132
|
-
- spec/state_machine_definition_spec.rb
|
133
|
-
- spec/state_machine_spec.rb
|
134
|
-
has_rdoc: true
|
39
|
+
- lib/tasks/graphviz.rake
|
135
40
|
homepage: http://github.com/mdh/ssm
|
136
41
|
licenses: []
|
137
|
-
|
138
|
-
post_install_message:
|
139
|
-
rdoc_options:
|
140
|
-
- --charset=UTF-8
|
141
|
-
require_paths:
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- "--charset=UTF-8"
|
46
|
+
require_paths:
|
142
47
|
- lib
|
143
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
-
|
145
|
-
requirements:
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
146
50
|
- - ">="
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
version: "0"
|
152
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
|
-
requirements:
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
155
55
|
- - ">="
|
156
|
-
- !ruby/object:Gem::Version
|
157
|
-
|
158
|
-
segments:
|
159
|
-
- 0
|
160
|
-
version: "0"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
161
58
|
requirements: []
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
signing_key:
|
166
|
-
specification_version: 3
|
59
|
+
rubygems_version: 3.1.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
167
62
|
summary: A simple DSL to decorate existing methods with logic that guards state transitions.
|
168
|
-
test_files:
|
169
|
-
- spec/active_record_spec.rb
|
170
|
-
- spec/decorator_spec.rb
|
171
|
-
- spec/examples_spec.rb
|
172
|
-
- spec/mountable_spec.rb
|
173
|
-
- spec/simple_state_machine_spec.rb
|
174
|
-
- spec/spec_helper.rb
|
175
|
-
- spec/state_machine_definition_spec.rb
|
176
|
-
- spec/state_machine_spec.rb
|
63
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
*.swp
|
data/.rspec
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
4
|
-
#require 'spec/rake/spectask'
|
5
|
-
#Spec::Rake::SpecTask.new(:spec) do |spec|
|
6
|
-
# spec.libs << 'lib' << 'spec'
|
7
|
-
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
8
|
-
#end
|
9
|
-
#
|
10
|
-
#Spec::Rake::SpecTask.new(:rcov) do |spec|
|
11
|
-
# spec.libs << 'lib' << 'spec'
|
12
|
-
# spec.pattern = 'spec/**/*_spec.rb'
|
13
|
-
# spec.rcov = true
|
14
|
-
#end
|
15
|
-
#
|
16
|
-
#task :spec => :check_dependencies
|
17
|
-
#
|
18
|
-
#task :default => :spec
|
19
|
-
|
20
|
-
require 'rake/rdoctask'
|
21
|
-
Rake::RDocTask.new do |rdoc|
|
22
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
23
|
-
|
24
|
-
rdoc.rdoc_dir = 'rdoc'
|
25
|
-
rdoc.title = "simple_state_machine #{version}"
|
26
|
-
rdoc.rdoc_files.include('README*')
|
27
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
28
|
-
end
|
data/autotest/discover.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Autotest.add_discovery { "rspec2" }
|
data/examples/conversation.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# Implementation of the AASM Conversation
|
2
|
-
#
|
3
|
-
# class Conversation
|
4
|
-
# include AASM
|
5
|
-
#
|
6
|
-
# aasm_column :current_state # defaults to aasm_state
|
7
|
-
#
|
8
|
-
# aasm_initial_state :unread
|
9
|
-
#
|
10
|
-
# aasm_state :unread
|
11
|
-
# aasm_state :read
|
12
|
-
# aasm_state :closed
|
13
|
-
#
|
14
|
-
# aasm_event :view do
|
15
|
-
# transitions :to => :read, :from => [:unread]
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# aasm_event :close do
|
19
|
-
# transitions :to => :closed, :from => [:read, :unread]
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
|
23
|
-
class Conversation
|
24
|
-
extend SimpleStateMachine
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
self.state = 'unread'
|
28
|
-
end
|
29
|
-
|
30
|
-
event :view, :unread => :read
|
31
|
-
event :close, :all => :closed
|
32
|
-
|
33
|
-
end
|
data/examples/lamp.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Lamp
|
2
|
-
|
3
|
-
extend SimpleStateMachine
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.state = 'off'
|
7
|
-
end
|
8
|
-
|
9
|
-
def push_button1
|
10
|
-
puts "click1: #{state}"
|
11
|
-
end
|
12
|
-
event :push_button1, :off => :on,
|
13
|
-
:on => :off
|
14
|
-
|
15
|
-
def push_button2
|
16
|
-
puts "click2: #{state}"
|
17
|
-
end
|
18
|
-
event :push_button2, :off => :on,
|
19
|
-
:on => :off
|
20
|
-
|
21
|
-
end
|
data/examples/relationship.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# Implementation of the AASM Conversation
|
2
|
-
#
|
3
|
-
# class Relationship
|
4
|
-
# include AASM
|
5
|
-
#
|
6
|
-
# aasm_column :status
|
7
|
-
#
|
8
|
-
# aasm_initial_state Proc.new { |relationship| relationship.strictly_for_fun? ? :intimate : :dating }
|
9
|
-
#
|
10
|
-
# aasm_state :dating, :enter => :make_happy, :exit => :make_depressed
|
11
|
-
# aasm_state :intimate, :enter => :make_very_happy, :exit => :never_speak_again
|
12
|
-
# aasm_state :married, :enter => :give_up_intimacy, :exit => :buy_exotic_car_and_wear_a_combover
|
13
|
-
#
|
14
|
-
# aasm_event :get_intimate do
|
15
|
-
# transitions :to => :intimate, :from => [:dating], :guard => :drunk?
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# aasm_event :get_married do
|
19
|
-
# transitions :to => :married, :from => [:dating, :intimate], :guard => :willing_to_give_up_manhood?
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# def strictly_for_fun?; end
|
23
|
-
# def drunk?; end
|
24
|
-
# def willing_to_give_up_manhood?; end
|
25
|
-
# def make_happy; end
|
26
|
-
# def make_depressed; end
|
27
|
-
# def make_very_happy; end
|
28
|
-
# def never_speak_again; end
|
29
|
-
# def give_up_intimacy; end
|
30
|
-
# def buy_exotic_car_and_wear_a_combover; end
|
31
|
-
# end
|
32
|
-
|
33
|
-
class Relationship
|
34
|
-
extend SimpleStateMachine
|
35
|
-
|
36
|
-
def initialize
|
37
|
-
self.state = relationship.strictly_for_fun? ? get_intimate : start_dating
|
38
|
-
end
|
39
|
-
|
40
|
-
def start_dating
|
41
|
-
make_happy
|
42
|
-
# make_depressed not called on exit
|
43
|
-
end
|
44
|
-
event :start_dating, nil => :dating
|
45
|
-
|
46
|
-
def get_intimate
|
47
|
-
# exit if drunk?
|
48
|
-
make_very_happy
|
49
|
-
# never_speak_again not called on exit
|
50
|
-
end
|
51
|
-
event :get_intimate, :dating => :intimate
|
52
|
-
|
53
|
-
def get_married
|
54
|
-
give_up_intimacy
|
55
|
-
#exit unless willing_to_give_up_manhood?
|
56
|
-
# buy_exotic_car_and_wear_a_combover not called on exit
|
57
|
-
end
|
58
|
-
event :get_married, :dating => :married,
|
59
|
-
:intimate => :married
|
60
|
-
|
61
|
-
# extra event added
|
62
|
-
def stop_dating
|
63
|
-
make_depressed
|
64
|
-
end
|
65
|
-
event :stop_dating, :dating => nil
|
66
|
-
|
67
|
-
def dump
|
68
|
-
never_speak_again
|
69
|
-
end
|
70
|
-
event :dump, :intimate => :dump
|
71
|
-
|
72
|
-
def divorce
|
73
|
-
buy_exotic_car_and_wear_a_combover
|
74
|
-
end
|
75
|
-
event :divorce, :married => :divorced
|
76
|
-
|
77
|
-
|
78
|
-
def strictly_for_fun?; end
|
79
|
-
def drunk?; end
|
80
|
-
def willing_to_give_up_manhood?; end
|
81
|
-
def make_happy; end
|
82
|
-
def make_depressed; end
|
83
|
-
def make_very_happy; end
|
84
|
-
def never_speak_again; end
|
85
|
-
def give_up_intimacy; end
|
86
|
-
def buy_exotic_car_and_wear_a_combover; end
|
87
|
-
end
|
data/examples/traffic_light.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
class TrafficLight
|
2
|
-
|
3
|
-
extend SimpleStateMachine
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.state = 'green'
|
7
|
-
end
|
8
|
-
|
9
|
-
# state machine events
|
10
|
-
def change_state
|
11
|
-
puts "#{state} => #{@next_state}"
|
12
|
-
end
|
13
|
-
|
14
|
-
event :change_state, :green => :orange,
|
15
|
-
:orange => :red,
|
16
|
-
:red => :green
|
17
|
-
end
|
data/examples/user.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'digest/sha1'
|
2
|
-
class User < ActiveRecord::Base
|
3
|
-
|
4
|
-
validates_presence_of :name
|
5
|
-
|
6
|
-
extend SimpleStateMachine::ActiveRecord
|
7
|
-
|
8
|
-
def after_initialize
|
9
|
-
self.state ||= 'new'
|
10
|
-
end
|
11
|
-
|
12
|
-
def invite
|
13
|
-
self.activation_code = Digest::SHA1.hexdigest("salt #{Time.now.to_f}")
|
14
|
-
send_activation_email(self.activation_code)
|
15
|
-
end
|
16
|
-
event :invite, :new => :invited
|
17
|
-
|
18
|
-
def confirm_invitation activation_code
|
19
|
-
if self.activation_code != activation_code
|
20
|
-
errors.add 'activation_code', 'is invalid'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
event :confirm_invitation, :invited => :active
|
24
|
-
|
25
|
-
#event :log_send_activation_code_failed, :new => :send_activation_code_failed
|
26
|
-
#
|
27
|
-
# def reset_password(new_password)
|
28
|
-
# self.password = new_password
|
29
|
-
# end
|
30
|
-
# # do not change state, but ensure that we are in proper state
|
31
|
-
# event :reset_password, :active => :active
|
32
|
-
|
33
|
-
def send_activation_email(code)
|
34
|
-
true
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/lib/tasks/graphiz.rake
DELETED
@@ -1,13 +0,0 @@
|
|
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
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "simple_state_machine/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = %q{simple_state_machine}
|
7
|
-
s.version = SimpleStateMachine::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
|
10
|
-
s.authors = ["Marek de Heus", "Petrik de Heus"]
|
11
|
-
s.description = %q{Simple State Machine is a state machine that focuses on events instead of states}
|
12
|
-
s.email = ["FIX@example.com"]
|
13
|
-
s.homepage = %q{http://github.com/mdh/ssm}
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"LICENSE",
|
16
|
-
"README.rdoc"
|
17
|
-
]
|
18
|
-
s.files = `git ls-files`.split("\n")
|
19
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
21
|
-
s.require_paths = ["lib"]
|
22
|
-
s.rubygems_version = %q{1.3.7}
|
23
|
-
s.summary = %q{A simple DSL to decorate existing methods with logic that guards state transitions.}
|
24
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
-
s.add_development_dependency "rake"
|
26
|
-
s.add_development_dependency "ZenTest"
|
27
|
-
s.add_development_dependency "rspec"
|
28
|
-
s.add_development_dependency "activerecord", "~>2.3.5"
|
29
|
-
s.add_development_dependency "sqlite3-ruby"
|
30
|
-
end
|
31
|
-
|