stateflow 0.4.2 → 0.5.0.beta
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/Gemfile.lock +2 -1
- data/Manifest +2 -1
- data/Rakefile +2 -1
- data/benchmark/compare_state_machines.rb +88 -0
- data/lib/stateflow.rb +9 -5
- data/lib/stateflow/persistence.rb +22 -14
- data/lib/stateflow/persistence/active_record.rb +4 -5
- data/lib/stateflow/persistence/mongo_mapper.rb +4 -5
- data/lib/stateflow/persistence/mongoid.rb +5 -6
- data/lib/stateflow/persistence/none.rb +2 -4
- data/lib/stateflow/railtie.rb +12 -0
- data/spec/stateflow_spec.rb +4 -0
- data/stateflow.gemspec +7 -4
- metadata +25 -11
data/Gemfile.lock
CHANGED
data/Manifest
CHANGED
@@ -5,6 +5,7 @@ LICENCE
|
|
5
5
|
Manifest
|
6
6
|
README.rdoc
|
7
7
|
Rakefile
|
8
|
+
benchmark/compare_state_machines.rb
|
8
9
|
examples/robot.rb
|
9
10
|
examples/test.rb
|
10
11
|
init.rb
|
@@ -17,10 +18,10 @@ lib/stateflow/persistence/active_record.rb
|
|
17
18
|
lib/stateflow/persistence/mongo_mapper.rb
|
18
19
|
lib/stateflow/persistence/mongoid.rb
|
19
20
|
lib/stateflow/persistence/none.rb
|
21
|
+
lib/stateflow/railtie.rb
|
20
22
|
lib/stateflow/state.rb
|
21
23
|
lib/stateflow/transition.rb
|
22
24
|
spec/orm/activerecord_spec.rb
|
23
25
|
spec/orm/mongoid_spec.rb
|
24
26
|
spec/spec_helper.rb
|
25
27
|
spec/stateflow_spec.rb
|
26
|
-
stateflow.gemspec
|
data/Rakefile
CHANGED
@@ -2,11 +2,12 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('stateflow', '0.
|
5
|
+
Echoe.new('stateflow', '0.5.0.beta') 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"
|
9
9
|
p.email = "ryan@platform45.com"
|
10
10
|
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.dependencies = ["activesupport"]
|
11
12
|
p.development_dependencies = ["rspec >=2.0.0", "activerecord", "mongoid >=2.0.0.beta.20", "sqlite3-ruby"]
|
12
13
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'active_record'
|
3
|
+
require 'stateflow'
|
4
|
+
require 'aasm'
|
5
|
+
|
6
|
+
# change this if sqlite is unavailable
|
7
|
+
dbconfig = {
|
8
|
+
:adapter => 'sqlite3',
|
9
|
+
:database => ':memory:'
|
10
|
+
}
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection(dbconfig)
|
13
|
+
ActiveRecord::Migration.verbose = false
|
14
|
+
|
15
|
+
|
16
|
+
class TestMigration < ActiveRecord::Migration
|
17
|
+
STATE_MACHINES = ['stateflow', 'aasm']
|
18
|
+
|
19
|
+
def self.up
|
20
|
+
STATE_MACHINES.each do |name|
|
21
|
+
create_table "#{name}_tests", :force => true do |t|
|
22
|
+
t.column :state, :string
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.down
|
28
|
+
STATE_MACHINES.each do |name|
|
29
|
+
drop_table "#{name}_tests"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Stateflow.persistence = :active_record
|
35
|
+
|
36
|
+
class StateflowTest < ActiveRecord::Base
|
37
|
+
include Stateflow
|
38
|
+
|
39
|
+
stateflow do
|
40
|
+
initial :green
|
41
|
+
|
42
|
+
state :green, :yellow, :red
|
43
|
+
|
44
|
+
event :change_color do
|
45
|
+
transitions :from => :green, :to => :yellow
|
46
|
+
transitions :from => :yellow, :to => :red
|
47
|
+
transitions :from => :red, :to => :green
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class AasmTest < ActiveRecord::Base
|
53
|
+
include AASM
|
54
|
+
|
55
|
+
aasm_column :state # defaults to aasm_state
|
56
|
+
|
57
|
+
aasm_initial_state :green
|
58
|
+
|
59
|
+
aasm_state :green
|
60
|
+
aasm_state :yellow
|
61
|
+
aasm_state :red
|
62
|
+
|
63
|
+
aasm_event :change_color do
|
64
|
+
transitions :from => :green, :to => :yellow
|
65
|
+
transitions :from => :yellow, :to => :red
|
66
|
+
transitions :from => :red, :to => :green
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
n = 1000
|
71
|
+
TestMigration.up
|
72
|
+
|
73
|
+
Benchmark.bm(7) do |x|
|
74
|
+
x.report('stateflow') do
|
75
|
+
n.times do
|
76
|
+
stateflow = StateflowTest.new
|
77
|
+
3.times { stateflow.change_color! }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
x.report('aasm') do
|
81
|
+
n.times do
|
82
|
+
aasm = AasmTest.new
|
83
|
+
3.times { aasm.change_color! }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
TestMigration.down
|
data/lib/stateflow.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
1
3
|
module Stateflow
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
Stateflow::Persistence.
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do |base|
|
7
|
+
Stateflow::Persistence.load!(base)
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.persistence
|
9
|
-
@@persistence ||=
|
11
|
+
@@persistence ||= nil
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.persistence=(persistence)
|
@@ -69,3 +71,5 @@ module Stateflow
|
|
69
71
|
autoload :Persistence, 'stateflow/persistence'
|
70
72
|
autoload :Exception, 'stateflow/exception'
|
71
73
|
end
|
74
|
+
|
75
|
+
require 'stateflow/railtie' if defined?(Rails)
|
@@ -1,21 +1,29 @@
|
|
1
1
|
module Stateflow
|
2
2
|
module Persistence
|
3
|
-
def self.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Stateflow::Persistence::ActiveRecord.install(base)
|
9
|
-
when :mongoid
|
10
|
-
Stateflow::Persistence::Mongoid.install(base)
|
11
|
-
when :none
|
12
|
-
Stateflow::Persistence::None.install(base)
|
3
|
+
def self.active
|
4
|
+
persistences = Array.new
|
5
|
+
|
6
|
+
Dir[File.dirname(__FILE__) + '/persistence/*.rb'].each do |file|
|
7
|
+
persistences << File.basename(file, File.extname(file)).underscore.to_sym
|
13
8
|
end
|
9
|
+
|
10
|
+
persistences
|
14
11
|
end
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def self.load!(base)
|
14
|
+
begin
|
15
|
+
base.send :include, "Stateflow::Persistence::#{Stateflow.persistence.to_s.camelize}".constantize
|
16
|
+
rescue NameError
|
17
|
+
puts "[Stateflow] The ORM you are using does not have a Persistence layer. Defaulting to ActiveRecord."
|
18
|
+
puts "[Stateflow] You can overwrite the persistence with Stateflow.persistence = :new_persistence_layer"
|
19
|
+
|
20
|
+
Stateflow.persistence = :active_record
|
21
|
+
base.send :include, "Stateflow::Persistence::ActiveRecord".constantize
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Stateflow::Persistence.active.each do |p|
|
26
|
+
autoload p.to_s.camelize.to_sym, "stateflow/persistence/#{p.to_s}"
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Stateflow
|
2
2
|
module Persistence
|
3
3
|
module ActiveRecord
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do |base|
|
7
|
+
base.before_validation(:ensure_initial_state, :on => :create)
|
9
8
|
end
|
10
9
|
|
11
10
|
module InstanceMethods
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Stateflow
|
2
2
|
module Persistence
|
3
3
|
module MongoMapper
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do |base|
|
7
|
+
base.before_validation(:ensure_initial_state, :on => :create)
|
9
8
|
end
|
10
9
|
|
11
10
|
module InstanceMethods
|
@@ -1,13 +1,12 @@
|
|
1
1
|
module Stateflow
|
2
2
|
module Persistence
|
3
3
|
module Mongoid
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do |base|
|
7
|
+
base.before_validation(:ensure_initial_state, :on => :create)
|
9
8
|
end
|
10
|
-
|
9
|
+
|
11
10
|
module InstanceMethods
|
12
11
|
def load_from_persistence
|
13
12
|
send machine.state_column.to_sym
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Stateflow
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
def default_orm
|
4
|
+
generators = config.respond_to?(:app_generators) ? :app_generators : :generators
|
5
|
+
config.send(generators).options[:rails][:orm]
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer "stateflow.set_persistence" do
|
9
|
+
Stateflow.persistence = default_orm if Stateflow.persistence.blank?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/stateflow_spec.rb
CHANGED
@@ -136,6 +136,10 @@ describe Stateflow do
|
|
136
136
|
it "should respond to the machine attr accessor" do
|
137
137
|
Robot.should respond_to(:machine)
|
138
138
|
end
|
139
|
+
|
140
|
+
it "should return all active persistence layers" do
|
141
|
+
Stateflow::Persistence.active.should == [:active_record, :mongo_mapper, :mongoid, :none]
|
142
|
+
end
|
139
143
|
end
|
140
144
|
|
141
145
|
describe "instance methods" do
|
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.5.0.beta"
|
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{2011-04-
|
9
|
+
s.date = %q{2011-04-08}
|
10
10
|
s.description = %q{State machine that allows dynamic transitions for business workflows}
|
11
11
|
s.email = %q{ryan@platform45.com}
|
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", "Gemfile", "Gemfile.lock", "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/orm/activerecord_spec.rb", "spec/orm/mongoid_spec.rb", "spec/spec_helper.rb", "spec/stateflow_spec.rb", "stateflow.gemspec"]
|
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/railtie.rb", "lib/stateflow/state.rb", "lib/stateflow/transition.rb"]
|
13
|
+
s.files = ["CHANGELOG.rdoc", "Gemfile", "Gemfile.lock", "LICENCE", "Manifest", "README.rdoc", "Rakefile", "benchmark/compare_state_machines.rb", "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/railtie.rb", "lib/stateflow/state.rb", "lib/stateflow/transition.rb", "spec/orm/activerecord_spec.rb", "spec/orm/mongoid_spec.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"]
|
@@ -22,17 +22,20 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.specification_version = 3
|
23
23
|
|
24
24
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
25
26
|
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
26
27
|
s.add_development_dependency(%q<activerecord>, [">= 0"])
|
27
28
|
s.add_development_dependency(%q<mongoid>, [">= 2.0.0.beta.20"])
|
28
29
|
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
29
30
|
else
|
31
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
30
32
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
31
33
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
32
34
|
s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.20"])
|
33
35
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
34
36
|
end
|
35
37
|
else
|
38
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
36
39
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
37
40
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
38
41
|
s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.20"])
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stateflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.5.0.beta
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Oberholzer
|
@@ -10,53 +10,64 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-08 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
17
|
+
name: activesupport
|
18
18
|
prerelease: false
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
20
31
|
none: false
|
21
32
|
requirements:
|
22
33
|
- - ">="
|
23
34
|
- !ruby/object:Gem::Version
|
24
35
|
version: 2.0.0
|
25
36
|
type: :development
|
26
|
-
version_requirements: *
|
37
|
+
version_requirements: *id002
|
27
38
|
- !ruby/object:Gem::Dependency
|
28
39
|
name: activerecord
|
29
40
|
prerelease: false
|
30
|
-
requirement: &
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
31
42
|
none: false
|
32
43
|
requirements:
|
33
44
|
- - ">="
|
34
45
|
- !ruby/object:Gem::Version
|
35
46
|
version: "0"
|
36
47
|
type: :development
|
37
|
-
version_requirements: *
|
48
|
+
version_requirements: *id003
|
38
49
|
- !ruby/object:Gem::Dependency
|
39
50
|
name: mongoid
|
40
51
|
prerelease: false
|
41
|
-
requirement: &
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
42
53
|
none: false
|
43
54
|
requirements:
|
44
55
|
- - ">="
|
45
56
|
- !ruby/object:Gem::Version
|
46
57
|
version: 2.0.0.beta.20
|
47
58
|
type: :development
|
48
|
-
version_requirements: *
|
59
|
+
version_requirements: *id004
|
49
60
|
- !ruby/object:Gem::Dependency
|
50
61
|
name: sqlite3-ruby
|
51
62
|
prerelease: false
|
52
|
-
requirement: &
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
53
64
|
none: false
|
54
65
|
requirements:
|
55
66
|
- - ">="
|
56
67
|
- !ruby/object:Gem::Version
|
57
68
|
version: "0"
|
58
69
|
type: :development
|
59
|
-
version_requirements: *
|
70
|
+
version_requirements: *id005
|
60
71
|
description: State machine that allows dynamic transitions for business workflows
|
61
72
|
email: ryan@platform45.com
|
62
73
|
executables: []
|
@@ -75,6 +86,7 @@ extra_rdoc_files:
|
|
75
86
|
- lib/stateflow/persistence/mongo_mapper.rb
|
76
87
|
- lib/stateflow/persistence/mongoid.rb
|
77
88
|
- lib/stateflow/persistence/none.rb
|
89
|
+
- lib/stateflow/railtie.rb
|
78
90
|
- lib/stateflow/state.rb
|
79
91
|
- lib/stateflow/transition.rb
|
80
92
|
files:
|
@@ -85,6 +97,7 @@ files:
|
|
85
97
|
- Manifest
|
86
98
|
- README.rdoc
|
87
99
|
- Rakefile
|
100
|
+
- benchmark/compare_state_machines.rb
|
88
101
|
- examples/robot.rb
|
89
102
|
- examples/test.rb
|
90
103
|
- init.rb
|
@@ -97,6 +110,7 @@ files:
|
|
97
110
|
- lib/stateflow/persistence/mongo_mapper.rb
|
98
111
|
- lib/stateflow/persistence/mongoid.rb
|
99
112
|
- lib/stateflow/persistence/none.rb
|
113
|
+
- lib/stateflow/railtie.rb
|
100
114
|
- lib/stateflow/state.rb
|
101
115
|
- lib/stateflow/transition.rb
|
102
116
|
- spec/orm/activerecord_spec.rb
|