rails_state_machine 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +9 -8
- data/CHANGELOG.md +14 -0
- data/Gemfile.5.1.pg.lock +2 -2
- data/Gemfile.5.2.pg.lock +2 -2
- data/Gemfile.6.0.pg.lock +2 -2
- data/Gemfile.6.1.pg.lock +1 -1
- data/Gemfile.7.0.pg +15 -0
- data/Gemfile.7.0.pg.lock +177 -0
- data/README.md +14 -3
- data/lib/rails_state_machine/model.rb +3 -3
- data/lib/rails_state_machine/state_machine.rb +27 -4
- data/lib/rails_state_machine/version.rb +1 -1
- data/rails_state_machine.gemspec +1 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f07991f6a0bc2dab134bc8518199885d79d0ee49d1865043a5e805e71c04b2b8
|
4
|
+
data.tar.gz: b4d3ba7b43eaed7a95522df3b385147f6feefbfac8a7b9dd7c49c6089731d037
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a5c81c9136fc6181974e7de5cd4a664f481c965098f39af45a3998b5cc3f29c9a46e0e983d5ca2cb724915505143c09643b93ade5a6bf3d47590af6ab716147
|
7
|
+
data.tar.gz: af45d14e32f278bc0a4e1d1dc76b9f7863300e178d87b032f7217c7aa4df1987740a5fb895b055058b6fb7fb1ca4e08cc3021c2d6b2bafc62c44ac1f15f23d94
|
data/.github/workflows/test.yml
CHANGED
@@ -23,26 +23,27 @@ jobs:
|
|
23
23
|
fail-fast: false
|
24
24
|
matrix:
|
25
25
|
include:
|
26
|
-
- ruby: 2.3.8
|
27
|
-
gemfile: Gemfile.5.1.pg
|
28
|
-
- ruby: 2.4.6
|
29
|
-
gemfile: Gemfile.5.1.pg
|
30
|
-
- ruby: 2.3.8
|
31
|
-
gemfile: Gemfile.5.2.pg
|
32
|
-
- ruby: 2.4.6
|
33
|
-
gemfile: Gemfile.5.2.pg
|
34
26
|
- ruby: 2.5.6
|
35
27
|
gemfile: Gemfile.5.2.pg
|
36
28
|
- ruby: 2.5.6
|
37
29
|
gemfile: Gemfile.6.0.pg
|
30
|
+
|
31
|
+
- ruby: 2.6.6
|
32
|
+
gemfile: Gemfile.5.2.pg
|
38
33
|
- ruby: 2.6.6
|
39
34
|
gemfile: Gemfile.6.0.pg
|
35
|
+
|
40
36
|
- ruby: 2.7.2
|
41
37
|
gemfile: Gemfile.6.0.pg
|
42
38
|
- ruby: 2.7.2
|
43
39
|
gemfile: Gemfile.6.1.pg
|
40
|
+
- ruby: 2.7.2
|
41
|
+
gemfile: Gemfile.7.0.pg
|
42
|
+
|
44
43
|
- ruby: 3.0.0
|
45
44
|
gemfile: Gemfile.6.1.pg
|
45
|
+
- ruby: 3.0.0
|
46
|
+
gemfile: Gemfile.7.0.pg
|
46
47
|
env:
|
47
48
|
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
|
48
49
|
steps:
|
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,20 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
10
10
|
### Breaking changes
|
11
11
|
|
12
12
|
|
13
|
+
## 2.2.0 2023-12-06
|
14
|
+
|
15
|
+
### Compatible changes
|
16
|
+
|
17
|
+
- Added: State machine can now use the `:prefix` option to avoid name collision if you define multiple state machines
|
18
|
+
on the same model, and use state names more than once
|
19
|
+
- Fix bug where additional inclusions of `RailsStateMachine::Model` would reset previous defined state machines
|
20
|
+
|
21
|
+
## 2.1.1 2022-03-16
|
22
|
+
|
23
|
+
### Compatible changes
|
24
|
+
|
25
|
+
- Enabled MFA for RubyGems
|
26
|
+
|
13
27
|
## 2.1.0 2021-03-30
|
14
28
|
|
15
29
|
### Compatible changes
|
data/Gemfile.5.1.pg.lock
CHANGED
data/Gemfile.5.2.pg.lock
CHANGED
data/Gemfile.6.0.pg.lock
CHANGED
data/Gemfile.6.1.pg.lock
CHANGED
data/Gemfile.7.0.pg
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Runtime dependencies
|
4
|
+
gem 'rails', '~>7.0.0'
|
5
|
+
gem 'pg'
|
6
|
+
|
7
|
+
# Development dependencies
|
8
|
+
gem 'rspec', '~>3.5'
|
9
|
+
gem 'rake'
|
10
|
+
gem 'pry-byebug'
|
11
|
+
gem 'gemika'
|
12
|
+
gem 'database_cleaner'
|
13
|
+
|
14
|
+
# Gem under test
|
15
|
+
gem 'rails_state_machine', :path => '.'
|
data/Gemfile.7.0.pg.lock
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails_state_machine (2.2.0)
|
5
|
+
activerecord
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (7.0.0)
|
11
|
+
actionpack (= 7.0.0)
|
12
|
+
activesupport (= 7.0.0)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (7.0.0)
|
16
|
+
actionpack (= 7.0.0)
|
17
|
+
activejob (= 7.0.0)
|
18
|
+
activerecord (= 7.0.0)
|
19
|
+
activestorage (= 7.0.0)
|
20
|
+
activesupport (= 7.0.0)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
actionmailer (7.0.0)
|
23
|
+
actionpack (= 7.0.0)
|
24
|
+
actionview (= 7.0.0)
|
25
|
+
activejob (= 7.0.0)
|
26
|
+
activesupport (= 7.0.0)
|
27
|
+
mail (~> 2.5, >= 2.5.4)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
actionpack (7.0.0)
|
30
|
+
actionview (= 7.0.0)
|
31
|
+
activesupport (= 7.0.0)
|
32
|
+
rack (~> 2.0, >= 2.2.0)
|
33
|
+
rack-test (>= 0.6.3)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
+
actiontext (7.0.0)
|
37
|
+
actionpack (= 7.0.0)
|
38
|
+
activerecord (= 7.0.0)
|
39
|
+
activestorage (= 7.0.0)
|
40
|
+
activesupport (= 7.0.0)
|
41
|
+
globalid (>= 0.6.0)
|
42
|
+
nokogiri (>= 1.8.5)
|
43
|
+
actionview (7.0.0)
|
44
|
+
activesupport (= 7.0.0)
|
45
|
+
builder (~> 3.1)
|
46
|
+
erubi (~> 1.4)
|
47
|
+
rails-dom-testing (~> 2.0)
|
48
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
+
activejob (7.0.0)
|
50
|
+
activesupport (= 7.0.0)
|
51
|
+
globalid (>= 0.3.6)
|
52
|
+
activemodel (7.0.0)
|
53
|
+
activesupport (= 7.0.0)
|
54
|
+
activerecord (7.0.0)
|
55
|
+
activemodel (= 7.0.0)
|
56
|
+
activesupport (= 7.0.0)
|
57
|
+
activestorage (7.0.0)
|
58
|
+
actionpack (= 7.0.0)
|
59
|
+
activejob (= 7.0.0)
|
60
|
+
activerecord (= 7.0.0)
|
61
|
+
activesupport (= 7.0.0)
|
62
|
+
marcel (~> 1.0)
|
63
|
+
mini_mime (>= 1.1.0)
|
64
|
+
activesupport (7.0.0)
|
65
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
|
+
i18n (>= 1.6, < 2)
|
67
|
+
minitest (>= 5.1)
|
68
|
+
tzinfo (~> 2.0)
|
69
|
+
builder (3.2.4)
|
70
|
+
byebug (11.1.3)
|
71
|
+
coderay (1.1.3)
|
72
|
+
concurrent-ruby (1.1.9)
|
73
|
+
crass (1.0.6)
|
74
|
+
database_cleaner (2.0.1)
|
75
|
+
database_cleaner-active_record (~> 2.0.0)
|
76
|
+
database_cleaner-active_record (2.0.1)
|
77
|
+
activerecord (>= 5.a)
|
78
|
+
database_cleaner-core (~> 2.0.0)
|
79
|
+
database_cleaner-core (2.0.1)
|
80
|
+
diff-lcs (1.4.4)
|
81
|
+
erubi (1.10.0)
|
82
|
+
gemika (0.6.1)
|
83
|
+
globalid (1.0.0)
|
84
|
+
activesupport (>= 5.0)
|
85
|
+
i18n (1.8.11)
|
86
|
+
concurrent-ruby (~> 1.0)
|
87
|
+
loofah (2.13.0)
|
88
|
+
crass (~> 1.0.2)
|
89
|
+
nokogiri (>= 1.5.9)
|
90
|
+
mail (2.7.1)
|
91
|
+
mini_mime (>= 0.1.1)
|
92
|
+
marcel (1.0.2)
|
93
|
+
method_source (1.0.0)
|
94
|
+
mini_mime (1.1.2)
|
95
|
+
mini_portile2 (2.6.1)
|
96
|
+
minitest (5.15.0)
|
97
|
+
nio4r (2.5.8)
|
98
|
+
nokogiri (1.12.5)
|
99
|
+
mini_portile2 (~> 2.6.1)
|
100
|
+
racc (~> 1.4)
|
101
|
+
nokogiri (1.12.5-x86_64-linux)
|
102
|
+
racc (~> 1.4)
|
103
|
+
pg (1.2.3)
|
104
|
+
pry (0.13.1)
|
105
|
+
coderay (~> 1.1)
|
106
|
+
method_source (~> 1.0)
|
107
|
+
pry-byebug (3.9.0)
|
108
|
+
byebug (~> 11.0)
|
109
|
+
pry (~> 0.13.0)
|
110
|
+
racc (1.6.0)
|
111
|
+
rack (2.2.3)
|
112
|
+
rack-test (1.1.0)
|
113
|
+
rack (>= 1.0, < 3)
|
114
|
+
rails (7.0.0)
|
115
|
+
actioncable (= 7.0.0)
|
116
|
+
actionmailbox (= 7.0.0)
|
117
|
+
actionmailer (= 7.0.0)
|
118
|
+
actionpack (= 7.0.0)
|
119
|
+
actiontext (= 7.0.0)
|
120
|
+
actionview (= 7.0.0)
|
121
|
+
activejob (= 7.0.0)
|
122
|
+
activemodel (= 7.0.0)
|
123
|
+
activerecord (= 7.0.0)
|
124
|
+
activestorage (= 7.0.0)
|
125
|
+
activesupport (= 7.0.0)
|
126
|
+
bundler (>= 1.15.0)
|
127
|
+
railties (= 7.0.0)
|
128
|
+
rails-dom-testing (2.0.3)
|
129
|
+
activesupport (>= 4.2.0)
|
130
|
+
nokogiri (>= 1.6)
|
131
|
+
rails-html-sanitizer (1.4.2)
|
132
|
+
loofah (~> 2.3)
|
133
|
+
railties (7.0.0)
|
134
|
+
actionpack (= 7.0.0)
|
135
|
+
activesupport (= 7.0.0)
|
136
|
+
method_source
|
137
|
+
rake (>= 12.2)
|
138
|
+
thor (~> 1.0)
|
139
|
+
zeitwerk (~> 2.5)
|
140
|
+
rake (13.0.6)
|
141
|
+
rspec (3.10.0)
|
142
|
+
rspec-core (~> 3.10.0)
|
143
|
+
rspec-expectations (~> 3.10.0)
|
144
|
+
rspec-mocks (~> 3.10.0)
|
145
|
+
rspec-core (3.10.1)
|
146
|
+
rspec-support (~> 3.10.0)
|
147
|
+
rspec-expectations (3.10.1)
|
148
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
149
|
+
rspec-support (~> 3.10.0)
|
150
|
+
rspec-mocks (3.10.2)
|
151
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
152
|
+
rspec-support (~> 3.10.0)
|
153
|
+
rspec-support (3.10.3)
|
154
|
+
thor (1.1.0)
|
155
|
+
tzinfo (2.0.4)
|
156
|
+
concurrent-ruby (~> 1.0)
|
157
|
+
websocket-driver (0.7.5)
|
158
|
+
websocket-extensions (>= 0.1.0)
|
159
|
+
websocket-extensions (0.1.5)
|
160
|
+
zeitwerk (2.5.1)
|
161
|
+
|
162
|
+
PLATFORMS
|
163
|
+
ruby
|
164
|
+
x86_64-linux
|
165
|
+
|
166
|
+
DEPENDENCIES
|
167
|
+
database_cleaner
|
168
|
+
gemika
|
169
|
+
pg
|
170
|
+
pry-byebug
|
171
|
+
rails (~> 7.0.0)
|
172
|
+
rails_state_machine!
|
173
|
+
rake
|
174
|
+
rspec (~> 3.5)
|
175
|
+
|
176
|
+
BUNDLED WITH
|
177
|
+
2.3.0
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ A model instance offers these state machine methods:
|
|
59
59
|
- `state_event=` to take a state event, but not save yet. Commonly used for forms where the controller takes a "state_event" param and saves.
|
60
60
|
- `state_event` to get the name of the event that will be called
|
61
61
|
|
62
|
-
Should you ever need to query the state machine for its states or events, it is accessible via `state_machine` class or instance methods on the model. This is mostly helpful in tests.
|
62
|
+
Should you ever need to query the state machine for its states or events, it is accessible via `state_machine` class or instance methods on the model. See [`state_machine.rb`](https://github.com/makandra/rails_state_machine/blob/master/lib/rails_state_machine/state_machine.rb) for a list of available methods. This is mostly helpful in tests.
|
63
63
|
|
64
64
|
If you want an event to be available for a different edge in your graph, you may define multiple `transitions` per event:
|
65
65
|
|
@@ -107,7 +107,7 @@ end
|
|
107
107
|
|
108
108
|
To use a state attribute other than the default `state`, pass it to the `.state_machine` method:
|
109
109
|
|
110
|
-
```
|
110
|
+
```ruby
|
111
111
|
state_machine :review_state do
|
112
112
|
# ...
|
113
113
|
end
|
@@ -116,13 +116,24 @@ end
|
|
116
116
|
This also allows you to define multiple state machines on the same model. Note that event
|
117
117
|
and state names still have to be unique for the whole model.
|
118
118
|
|
119
|
+
If you define multiple state machines on the same model, and use state names more than once,
|
120
|
+
you must use a prefix to avoid name collisions.
|
121
|
+
|
122
|
+
A prefix may be specified by passing the `:prefix` option when declaring your state machine:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
state_machine :review_state, prefix: 'some_prefix' do
|
126
|
+
# ...
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
119
130
|
|
120
131
|
## Taking multiple transitions
|
121
132
|
|
122
133
|
You can safely take a second transition inside an after_save callback. All relevant
|
123
134
|
callbacks will be run.
|
124
135
|
|
125
|
-
```
|
136
|
+
```ruby
|
126
137
|
state_machine do
|
127
138
|
state :draft, initial: true
|
128
139
|
state :review_pending
|
@@ -7,15 +7,15 @@ module RailsStateMachine
|
|
7
7
|
extend ClassMethods
|
8
8
|
|
9
9
|
cattr_accessor :state_machines
|
10
|
-
self.state_machines
|
10
|
+
self.state_machines ||= {}
|
11
11
|
|
12
12
|
delegate :state_machine, to: :class
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
|
-
def state_machine(state_attribute = DEFAULT_STATE_ATTRIBUTE, &block)
|
18
|
-
state_machine = state_machines[state_attribute] ||= StateMachine.new(self, state_attribute)
|
17
|
+
def state_machine(state_attribute = DEFAULT_STATE_ATTRIBUTE, prefix: '', &block)
|
18
|
+
state_machine = state_machines[state_attribute] ||= StateMachine.new(self, state_attribute, prefix: prefix)
|
19
19
|
if block
|
20
20
|
include(Callbacks) unless self < Callbacks
|
21
21
|
state_machine.configure(&block)
|
@@ -1,18 +1,26 @@
|
|
1
1
|
module RailsStateMachine
|
2
2
|
class StateMachine
|
3
|
-
attr_reader :model
|
4
3
|
|
5
|
-
|
4
|
+
StateAlreadyDefinedError = Class.new(StandardError)
|
5
|
+
|
6
|
+
def initialize(model, state_attribute, prefix: '')
|
6
7
|
@model = model
|
7
8
|
@state_attribute = state_attribute
|
9
|
+
@prefix = prefix
|
10
|
+
@prefix_for_constant_definition = "#{@prefix.upcase}_" if @prefix.present?
|
11
|
+
@prefix_for_method_definition = "#{@prefix.downcase}_" if @prefix.present?
|
8
12
|
@states_by_name = {}
|
9
13
|
@events_by_name = {}
|
10
14
|
build_model_module
|
11
15
|
end
|
12
16
|
|
17
|
+
attr_reader :model, :prefix, :prefix_for_constant_definition, :prefix_for_method_definition, :state_attribute
|
18
|
+
|
13
19
|
def configure(&block)
|
14
20
|
instance_eval(&block)
|
15
21
|
|
22
|
+
check_if_states_already_defined
|
23
|
+
|
16
24
|
define_state_methods
|
17
25
|
define_state_constants
|
18
26
|
register_initial_state
|
@@ -74,11 +82,26 @@ module RailsStateMachine
|
|
74
82
|
@model_module.module_eval(&block)
|
75
83
|
end
|
76
84
|
|
85
|
+
def check_if_states_already_defined
|
86
|
+
@states_by_name.each do |state_name, _|
|
87
|
+
other_state_machines.each do |state_machine|
|
88
|
+
if state_machine.has_state?(state_name) && state_machine.prefix == prefix
|
89
|
+
raise StateAlreadyDefinedError, "State #{state_name.inspect} has already been defined in the #{state_machine.state_attribute.inspect} state machine. You may use the :prefix option when defining a state machine to avoid that."
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def other_state_machines
|
96
|
+
model.state_machines.except(@state_attribute).values
|
97
|
+
end
|
98
|
+
|
77
99
|
def define_state_methods
|
78
100
|
state_attribute = @state_attribute
|
101
|
+
prefix = prefix_for_method_definition
|
79
102
|
state_names.each do |state_name|
|
80
103
|
model_module_eval do
|
81
|
-
define_method "#{state_name}?" do
|
104
|
+
define_method "#{prefix}#{state_name}?" do
|
82
105
|
state_machine_state_manager(state_attribute).state == state_name.to_s
|
83
106
|
end
|
84
107
|
end
|
@@ -87,7 +110,7 @@ module RailsStateMachine
|
|
87
110
|
|
88
111
|
def define_state_constants
|
89
112
|
state_names.each do |state_name|
|
90
|
-
model_constant("STATE_#{state_name.upcase}", state_name)
|
113
|
+
model_constant("#{@prefix_for_constant_definition}STATE_#{state_name.upcase}", state_name)
|
91
114
|
end
|
92
115
|
end
|
93
116
|
|
data/rails_state_machine.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = spec.summary
|
13
13
|
spec.homepage = 'https://github.com/makandra/rails_state_machine'
|
14
14
|
spec.license = 'MIT'
|
15
|
+
spec.metadata = { 'rubygems_mfa_required' => 'true' }
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
18
|
f.match(%r{^(test|spec|features)/})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_state_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Hartherz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -88,6 +88,8 @@ files:
|
|
88
88
|
- Gemfile.6.0.pg.lock
|
89
89
|
- Gemfile.6.1.pg
|
90
90
|
- Gemfile.6.1.pg.lock
|
91
|
+
- Gemfile.7.0.pg
|
92
|
+
- Gemfile.7.0.pg.lock
|
91
93
|
- Gemfile.lock
|
92
94
|
- LICENSE
|
93
95
|
- LICENSE.txt
|
@@ -107,7 +109,8 @@ files:
|
|
107
109
|
homepage: https://github.com/makandra/rails_state_machine
|
108
110
|
licenses:
|
109
111
|
- MIT
|
110
|
-
metadata:
|
112
|
+
metadata:
|
113
|
+
rubygems_mfa_required: 'true'
|
111
114
|
post_install_message:
|
112
115
|
rdoc_options: []
|
113
116
|
require_paths:
|
@@ -123,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
126
|
- !ruby/object:Gem::Version
|
124
127
|
version: '0'
|
125
128
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
129
|
+
rubygems_version: 3.1.6
|
127
130
|
signing_key:
|
128
131
|
specification_version: 4
|
129
132
|
summary: ActiveRecord-bound state machine
|