stator 0.4.0 → 0.9.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +28 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Appraisals +23 -0
- data/Gemfile +4 -3
- data/gemfiles/activerecord_5.1.gemfile +12 -0
- data/gemfiles/activerecord_5.1.gemfile.lock +74 -0
- data/gemfiles/activerecord_5.2.gemfile +12 -0
- data/gemfiles/activerecord_5.2.gemfile.lock +74 -0
- data/gemfiles/activerecord_5.gemfile +12 -0
- data/gemfiles/activerecord_5.gemfile.lock +74 -0
- data/gemfiles/activerecord_6.0.gemfile +12 -0
- data/gemfiles/activerecord_6.0.gemfile.lock +74 -0
- data/gemfiles/activerecord_6.1.gemfile +12 -0
- data/gemfiles/activerecord_6.1.gemfile.lock +73 -0
- data/gemfiles/activerecord_7.0.gemfile +12 -0
- data/gemfiles/activerecord_7.0.gemfile.lock +71 -0
- data/lib/stator/alias.rb +51 -30
- data/lib/stator/integration.rb +42 -49
- data/lib/stator/machine.rb +59 -58
- data/lib/stator/model.rb +78 -73
- data/lib/stator/transition.rb +61 -60
- data/lib/stator/version.rb +3 -5
- data/lib/stator.rb +13 -0
- data/spec/model_spec.rb +206 -207
- data/spec/spec_helper.rb +6 -3
- data/spec/support/models.rb +26 -32
- data/spec/support/schema.rb +42 -42
- data/stator.gemspec +1 -0
- metadata +33 -10
- data/.travis.yml +0 -41
- data/gemfiles/ar40.gemfile +0 -10
- data/gemfiles/ar41.gemfile +0 -10
- data/gemfiles/ar42.gemfile +0 -10
- data/gemfiles/ar52.gemfile +0 -10
data/spec/support/models.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class User < ActiveRecord::Base
|
2
|
-
|
4
|
+
include Stator::Model
|
3
5
|
|
4
6
|
before_save :set_tagged_at
|
5
7
|
|
@@ -15,7 +17,7 @@ class User < ActiveRecord::Base
|
|
15
17
|
to :deactivated
|
16
18
|
|
17
19
|
conditional do |condition|
|
18
|
-
before_save :set_deactivated, :
|
20
|
+
before_save :set_deactivated, if: condition
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -24,7 +26,7 @@ class User < ActiveRecord::Base
|
|
24
26
|
to :semiactivated
|
25
27
|
|
26
28
|
conditional do |condition|
|
27
|
-
validate :check_email_validity, :
|
29
|
+
validate :check_email_validity, if: condition
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -34,19 +36,18 @@ class User < ActiveRecord::Base
|
|
34
36
|
end
|
35
37
|
|
36
38
|
conditional :semiactivated, :activated do |condition|
|
37
|
-
validate :check_email_presence, :
|
39
|
+
validate :check_email_presence, if: condition
|
38
40
|
end
|
39
41
|
|
40
|
-
state_alias :active, :
|
42
|
+
state_alias :active, constant: true, scope: true do
|
41
43
|
is :activated, :hyperactivated
|
42
|
-
opposite :inactive, :
|
44
|
+
opposite :inactive, constant: true, scope: true
|
43
45
|
end
|
44
46
|
|
45
|
-
state_alias :luke_warm, :
|
47
|
+
state_alias :luke_warm, constant: :luke_warmers, scope: :luke_warmers do
|
46
48
|
is :semiactivated
|
47
49
|
opposite :iced_tea
|
48
50
|
end
|
49
|
-
|
50
51
|
end
|
51
52
|
|
52
53
|
validate :email_is_right_length
|
@@ -54,8 +55,8 @@ class User < ActiveRecord::Base
|
|
54
55
|
protected
|
55
56
|
|
56
57
|
def check_email_presence
|
57
|
-
|
58
|
-
|
58
|
+
if email.nil? || email.empty?
|
59
|
+
errors.add(:email, 'needs to be present')
|
59
60
|
return false
|
60
61
|
end
|
61
62
|
|
@@ -63,8 +64,8 @@ class User < ActiveRecord::Base
|
|
63
64
|
end
|
64
65
|
|
65
66
|
def check_email_validity
|
66
|
-
unless
|
67
|
-
|
67
|
+
unless /example\.com$/.match?(email.to_s)
|
68
|
+
errors.add(:email, 'format needs to be example.com')
|
68
69
|
return false
|
69
70
|
end
|
70
71
|
|
@@ -72,8 +73,8 @@ class User < ActiveRecord::Base
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def email_is_right_length
|
75
|
-
unless
|
76
|
-
|
76
|
+
unless email.to_s.length == 'four@example.com'.length
|
77
|
+
errors.add(:email, 'needs to be the right length')
|
77
78
|
return false
|
78
79
|
end
|
79
80
|
|
@@ -86,32 +87,29 @@ class User < ActiveRecord::Base
|
|
86
87
|
end
|
87
88
|
|
88
89
|
def set_tagged_at
|
89
|
-
self.tagged_at =
|
90
|
+
self.tagged_at = semiactivated_state_at
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
94
|
class Animal < ActiveRecord::Base
|
94
|
-
|
95
|
+
include Stator::Model
|
95
96
|
|
96
97
|
# initial state = unborn
|
97
|
-
stator :
|
98
|
-
|
98
|
+
stator field: :status, track: true do
|
99
99
|
transition :birth do
|
100
100
|
from :unborn
|
101
101
|
to :born
|
102
102
|
end
|
103
103
|
|
104
104
|
state :grown_up
|
105
|
-
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
108
|
class Zoo < ActiveRecord::Base
|
110
|
-
|
109
|
+
include Stator::Model
|
111
110
|
|
112
111
|
# initial state = closed
|
113
112
|
stator do
|
114
|
-
|
115
113
|
transition :open do
|
116
114
|
from :closed
|
117
115
|
to :opened
|
@@ -123,7 +121,7 @@ class Zoo < ActiveRecord::Base
|
|
123
121
|
end
|
124
122
|
|
125
123
|
conditional :opened do |c|
|
126
|
-
validate :validate_lights_are_on, :
|
124
|
+
validate :validate_lights_are_on, if: c
|
127
125
|
end
|
128
126
|
end
|
129
127
|
|
@@ -135,7 +133,7 @@ class Zoo < ActiveRecord::Base
|
|
135
133
|
end
|
136
134
|
|
137
135
|
class ZooKeeper < ActiveRecord::Base
|
138
|
-
|
136
|
+
include Stator::Model
|
139
137
|
|
140
138
|
stator namespace: 'employment', field: 'employment_state', track: true do
|
141
139
|
transition :hire do
|
@@ -163,20 +161,18 @@ class ZooKeeper < ActiveRecord::Base
|
|
163
161
|
end
|
164
162
|
|
165
163
|
class Farm < ActiveRecord::Base
|
166
|
-
|
164
|
+
include Stator::Model
|
167
165
|
|
168
166
|
# initial state = dirty
|
169
167
|
stator do
|
170
168
|
transition :cleanup do
|
171
|
-
|
172
|
-
|
169
|
+
from :dirty
|
170
|
+
to :clean
|
173
171
|
end
|
174
172
|
end
|
175
173
|
|
176
|
-
|
177
174
|
# initial state = dirty
|
178
|
-
stator :
|
179
|
-
|
175
|
+
stator namespace: 'house', field: 'house_state' do
|
180
176
|
transition :cleanup do
|
181
177
|
from :dirty
|
182
178
|
to :clean
|
@@ -191,11 +187,10 @@ class Farm < ActiveRecord::Base
|
|
191
187
|
is_not :dirty, :disgusting
|
192
188
|
end
|
193
189
|
end
|
194
|
-
|
195
190
|
end
|
196
191
|
|
197
192
|
class Factory < ActiveRecord::Base
|
198
|
-
|
193
|
+
include Stator::Model
|
199
194
|
|
200
195
|
# initial state = nil
|
201
196
|
stator do
|
@@ -209,5 +204,4 @@ class Factory < ActiveRecord::Base
|
|
209
204
|
to :on_the_ground
|
210
205
|
end
|
211
206
|
end
|
212
|
-
|
213
207
|
end
|
data/spec/support/schema.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
t.string
|
6
|
-
t.
|
7
|
-
t.
|
8
|
-
t.
|
9
|
-
t.
|
10
|
-
t.datetime
|
11
|
-
t.datetime
|
12
|
-
t.datetime
|
3
|
+
ActiveRecord::Schema.define(version: 20_130_628_161_227) do
|
4
|
+
create_table 'users', force: true do |t|
|
5
|
+
t.string 'name'
|
6
|
+
t.string 'email'
|
7
|
+
t.datetime 'tagged_at'
|
8
|
+
t.string 'state', default: 'pending'
|
9
|
+
t.boolean 'activated', default: true
|
10
|
+
t.datetime 'created_at', null: false
|
11
|
+
t.datetime 'updated_at', null: false
|
12
|
+
t.datetime 'semiactivated_state_at'
|
13
|
+
t.datetime 'activated_state_at'
|
13
14
|
end
|
14
15
|
|
15
|
-
create_table
|
16
|
-
t.string
|
17
|
-
t.string
|
18
|
-
t.datetime
|
19
|
-
t.datetime
|
20
|
-
t.datetime
|
21
|
-
t.datetime
|
22
|
-
t.datetime
|
16
|
+
create_table 'animals', force: true do |t|
|
17
|
+
t.string 'name'
|
18
|
+
t.string 'status', default: 'unborn'
|
19
|
+
t.datetime 'created_at', null: false
|
20
|
+
t.datetime 'updated_at', null: false
|
21
|
+
t.datetime 'status_changed_at'
|
22
|
+
t.datetime 'unborn_status_at'
|
23
|
+
t.datetime 'born_status_at'
|
23
24
|
end
|
24
25
|
|
25
|
-
create_table
|
26
|
-
t.string
|
27
|
-
t.string
|
28
|
-
t.datetime
|
29
|
-
t.datetime
|
30
|
-
t.string
|
31
|
-
t.datetime
|
32
|
-
t.datetime
|
26
|
+
create_table 'zoo_keepers', force: true do |t|
|
27
|
+
t.string 'name'
|
28
|
+
t.string 'employment_state', default: 'hired'
|
29
|
+
t.datetime 'hired_employment_state_at'
|
30
|
+
t.datetime 'fired_employment_state_at'
|
31
|
+
t.string 'working_state'
|
32
|
+
t.datetime 'started_working_state_at'
|
33
|
+
t.datetime 'ended_working_state_at'
|
33
34
|
end
|
34
35
|
|
35
|
-
create_table
|
36
|
-
t.string
|
37
|
-
t.string
|
38
|
-
t.datetime
|
39
|
-
t.datetime
|
36
|
+
create_table 'zoos', force: true do |t|
|
37
|
+
t.string 'name'
|
38
|
+
t.string 'state', default: 'closed'
|
39
|
+
t.datetime 'created_at', null: false
|
40
|
+
t.datetime 'updated_at', null: false
|
40
41
|
end
|
41
42
|
|
42
|
-
create_table
|
43
|
-
t.string
|
44
|
-
t.string
|
45
|
-
t.string
|
46
|
-
t.datetime
|
47
|
-
t.datetime
|
43
|
+
create_table 'farms', force: true do |t|
|
44
|
+
t.string 'name'
|
45
|
+
t.string 'state', default: 'dirty'
|
46
|
+
t.string 'house_state', default: 'dirty'
|
47
|
+
t.datetime 'created_at', null: false
|
48
|
+
t.datetime 'updated_at', null: false
|
48
49
|
end
|
49
50
|
|
50
|
-
create_table
|
51
|
-
t.string
|
52
|
-
t.string
|
51
|
+
create_table 'factories', force: true do |t|
|
52
|
+
t.string 'name'
|
53
|
+
t.string 'state'
|
53
54
|
end
|
54
|
-
|
55
55
|
end
|
data/stator.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: The simplest of ActiveRecord state machines. Intended to be lightweight
|
28
42
|
and minimalistic.
|
29
43
|
email:
|
@@ -32,19 +46,28 @@ executables: []
|
|
32
46
|
extensions: []
|
33
47
|
extra_rdoc_files: []
|
34
48
|
files:
|
49
|
+
- ".github/workflows/build.yml"
|
35
50
|
- ".gitignore"
|
36
51
|
- ".rspec"
|
37
52
|
- ".ruby-gemset"
|
38
53
|
- ".ruby-version"
|
39
|
-
-
|
54
|
+
- Appraisals
|
40
55
|
- Gemfile
|
41
56
|
- LICENSE.txt
|
42
57
|
- README.md
|
43
58
|
- Rakefile
|
44
|
-
- gemfiles/
|
45
|
-
- gemfiles/
|
46
|
-
- gemfiles/
|
47
|
-
- gemfiles/
|
59
|
+
- gemfiles/activerecord_5.1.gemfile
|
60
|
+
- gemfiles/activerecord_5.1.gemfile.lock
|
61
|
+
- gemfiles/activerecord_5.2.gemfile
|
62
|
+
- gemfiles/activerecord_5.2.gemfile.lock
|
63
|
+
- gemfiles/activerecord_5.gemfile
|
64
|
+
- gemfiles/activerecord_5.gemfile.lock
|
65
|
+
- gemfiles/activerecord_6.0.gemfile
|
66
|
+
- gemfiles/activerecord_6.0.gemfile.lock
|
67
|
+
- gemfiles/activerecord_6.1.gemfile
|
68
|
+
- gemfiles/activerecord_6.1.gemfile.lock
|
69
|
+
- gemfiles/activerecord_7.0.gemfile
|
70
|
+
- gemfiles/activerecord_7.0.gemfile.lock
|
48
71
|
- lib/stator.rb
|
49
72
|
- lib/stator/alias.rb
|
50
73
|
- lib/stator/integration.rb
|
@@ -71,11 +94,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
94
|
version: '0'
|
72
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
96
|
requirements:
|
74
|
-
- - "
|
97
|
+
- - ">"
|
75
98
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
99
|
+
version: 1.3.1
|
77
100
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.1.6
|
79
102
|
signing_key:
|
80
103
|
specification_version: 4
|
81
104
|
summary: The simplest of ActiveRecord state machines
|
data/.travis.yml
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
rvm:
|
4
|
-
- 2.0.0
|
5
|
-
- 2.1.6
|
6
|
-
- 2.2.3
|
7
|
-
- 2.4.5
|
8
|
-
- 2.5.3
|
9
|
-
|
10
|
-
gemfile:
|
11
|
-
- gemfiles/ar40.gemfile
|
12
|
-
- gemfiles/ar41.gemfile
|
13
|
-
- gemfiles/ar42.gemfile
|
14
|
-
- gemfiles/ar52.gemfile
|
15
|
-
|
16
|
-
matrix:
|
17
|
-
allow_failures:
|
18
|
-
- gemfile: gemfiles/ar42.gemfile
|
19
|
-
- gemfile: gemfiles/ar52.gemfile
|
20
|
-
|
21
|
-
exclude:
|
22
|
-
- rvm: 2.0.0
|
23
|
-
gemfile: gemfiles/ar52.gemfile
|
24
|
-
|
25
|
-
- rvm: 2.1.6
|
26
|
-
gemfile: gemfiles/ar52.gemfile
|
27
|
-
|
28
|
-
- rvm: 2.2.3
|
29
|
-
gemfile: gemfiles/ar52.gemfile
|
30
|
-
|
31
|
-
- rvm: 2.4.5
|
32
|
-
gemfile: gemfiles/ar40.gemfile
|
33
|
-
|
34
|
-
- rvm: 2.4.5
|
35
|
-
gemfile: gemfiles/ar41.gemfile
|
36
|
-
|
37
|
-
- rvm: 2.5.3
|
38
|
-
gemfile: gemfiles/ar40.gemfile
|
39
|
-
|
40
|
-
- rvm: 2.5.3
|
41
|
-
gemfile: gemfiles/ar41.gemfile
|
data/gemfiles/ar40.gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '~> 4.0.0'
|
5
|
-
|
6
|
-
gemspec :path => '../'
|
7
|
-
|
8
|
-
gem 'rake'
|
9
|
-
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
10
|
-
gem 'rspec'
|
data/gemfiles/ar41.gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '~> 4.1.0'
|
5
|
-
|
6
|
-
gemspec :path => '../'
|
7
|
-
|
8
|
-
gem 'rake'
|
9
|
-
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
10
|
-
gem 'rspec'
|
data/gemfiles/ar42.gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '~> 4.0.0'
|
5
|
-
|
6
|
-
gemspec :path => '../'
|
7
|
-
|
8
|
-
gem 'rake'
|
9
|
-
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
10
|
-
gem 'rspec'
|
data/gemfiles/ar52.gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
4
|
-
gem 'activerecord', '~> 5.2.0'
|
5
|
-
|
6
|
-
gemspec :path => '../'
|
7
|
-
|
8
|
-
gem 'rake'
|
9
|
-
gem 'activerecord-nulldb-adapter', '~> 0.4.0', :require => false, :git => 'git@github.com:nulldb/nulldb.git'
|
10
|
-
gem 'rspec'
|