stator 0.9.0.beta → 0.9.0

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/Appraisals DELETED
@@ -1,23 +0,0 @@
1
- appraise "activerecord-5" do
2
- gem "activerecord", "~> 5.0.0"
3
- end
4
-
5
- appraise "activerecord-5.1" do
6
- gem "activerecord", "~> 5.1.0"
7
- end
8
-
9
- appraise "activerecord-5.2" do
10
- gem "activerecord", "~> 5.2.0"
11
- end
12
-
13
- appraise "activerecord-6.0" do
14
- gem "activerecord", "~> 6.0.0"
15
- end
16
-
17
- appraise "activerecord-6.1" do
18
- gem "activerecord", "~> 6.1.0"
19
- end
20
-
21
- appraise "activerecord-7.0" do
22
- gem "activerecord", "~> 7.0.0"
23
- end
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '~> 5.2.8'
4
-
5
- gemspec
6
-
7
- gem 'appraisal'
8
- gem 'debug'
9
- gem 'activerecord-nulldb-adapter'
10
- gem 'rake'
11
- gem 'rspec'
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Mike Nelson
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,214 +0,0 @@
1
- # Stator
2
-
3
- Stator is a minimalist's state machine. It's a simple dsl that uses existing ActiveRecord functionality to accomplish common state machine functionality. This is not a full-featured computer-science driven gem, it's a gem that covers the 98% of use cases that I've run into.
4
-
5
- ```ruby
6
- gem 'stator', '~> x.y.z'
7
- ```
8
-
9
- ## Usage
10
-
11
- If you've used the state_machine gem it's a pretty similar dsl. You define your state machine, transitions, states, and your callbacks (if any). One difference is that stator assumes you've set your db column's default value to the initial state.
12
-
13
- ```ruby
14
- class User < ActiveRecord::Base
15
- extend Stator::Model
16
-
17
- # initial state (column default) is "unactivated"
18
- stator do
19
-
20
- transition :semiactivate do
21
- from :unactivated
22
- to :semiactivated
23
- end
24
-
25
- transition :activate do
26
- from :unactivated, :semiactivated
27
- to :activated
28
- end
29
-
30
- transition :deactivate do
31
- from any
32
- to :deactivate
33
- end
34
-
35
- end
36
- end
37
- ```
38
-
39
- Then you use like this:
40
-
41
- ```ruby
42
- u = User.new
43
- u.state
44
- # => 'unactivated'
45
- u.persisted?
46
- # => false
47
- u.semiactivate
48
- # => true
49
- u.state
50
- # => 'semiactivated'
51
- u.persisted?
52
- # => true
53
- ```
54
-
55
- ## Advanced Usage
56
-
57
- The intention of stator was to avoid hijacking ActiveRecord or reinvent the wheel. You can conditionally validate, invoke callbacks, etc. via a conditional block - no magic:
58
-
59
- ```ruby
60
- class User < ActiveRecord::Base
61
- extend Stator::Model
62
-
63
- stator field: :status, track: true do
64
-
65
- transition :activate do
66
- from :unactivated
67
- to :activated
68
-
69
- # conditions is a string condition which will ensure the state
70
- # was one of the `from` states and is one of the `to` states.
71
- conditional do |conditions|
72
- validate :validate_user_ip_not_blacklisted, if: conditions
73
- end
74
-
75
- end
76
-
77
- # conditions is a string condition which will ensure the state
78
- # is one of the ones provided.
79
- conditional :unactivated do |conditions|
80
- validates :email, presence: true, unless: conditions
81
- end
82
-
83
- end
84
- end
85
- ```
86
-
87
- Within a transition, the `conditional` block accepts a `use_previous` option which tells the state checks to use the record's previous_changes rather than the current changes. This is especially useful for after_commit scenarios where the record's changes hash is cleared before the execution begins.
88
-
89
- ```ruby
90
- transition :activate do
91
- from :unactivated
92
- to :activated
93
-
94
- conditional(use_previous: true) do |conditions|
95
- after_commit :send_things, if: conditions
96
- end
97
- ```
98
-
99
- The instance has some convenience methods which are generated by the state machine:
100
-
101
- ```ruby
102
- u = User.new
103
- u.activated?
104
- # => false
105
- u.can_activate?
106
- # => true
107
- ```
108
-
109
- Note that asking if a transition can take place via `can_[transition_name]?` does not invoke validations. It simply determines whether the record is in a state which the transition can take place from.
110
-
111
-
112
- The `track: true` option enables timekeeping of the state transition. It will try to set a field in the format of "state_field_at" before saving the record. For example, in the previous state machine the following would occur:
113
-
114
- ```ruby
115
- u = User.new
116
- u.activate
117
-
118
- u.activated_status_at
119
- # => (now)
120
- ```
121
-
122
- `track: true` will also look for a "state_changed_at" field and will update that if it's present.
123
-
124
- You can have multiple state machines for your model:
125
-
126
- ```ruby
127
-
128
- class User < ActiveRecord::Base
129
- extend Stator::Model
130
-
131
- # initial state = asleep
132
- stator do
133
- # wake up
134
- end
135
-
136
- # initial state = incomplete
137
- stator namespace: 'homework', field: 'homework_state' do
138
- # get it done
139
- end
140
- end
141
- ```
142
-
143
-
144
- If you need to access the state machine directly, you can do so via the class:
145
-
146
- ```ruby
147
- User._stator(namespace)
148
- ```
149
-
150
- You can opt out of state transition validation by using the `without_state_transition_validations` method:
151
-
152
- ```ruby
153
- user.without_state_transition_validations do
154
- user.activate!
155
- end
156
- ```
157
-
158
- #### Aliasing
159
-
160
- It's a really common case to have a set of states evaluated as a single concept. For example, many apps have a concept of "active" users. You generally see something like this:
161
-
162
- ```ruby
163
- class User < ActiveRecord::Base
164
- ACTIVE_STATES = %w(semiactivated activated)
165
-
166
- scope :active, -> { where(state: ACTIVE_STATES) }
167
-
168
- def active?
169
- self.state.in?(ACTIVE_STATES)
170
- end
171
- end
172
- ```
173
-
174
- To this point, we're doing ok. But how about defining inactive as well? At this point things start getting a little dirtier since a change to ACTIVE_STATES should impact INACTIVE_STATES. For this reason, stator allows you to define state aliases:
175
-
176
- ```ruby
177
- class User < ActiveRecord::Base
178
- extend Stator::Model
179
-
180
- stator do
181
- # forgoing state definitions...
182
-
183
- state_alias :active do
184
- is :semiactivated, :activated
185
- opposite :inactive
186
- end
187
- end
188
- end
189
- ```
190
-
191
- The provided example will define an `active?` and `inactive?` method. If you want to create the constant and/or the scope, just pass them as options to the state_alias method:
192
-
193
- ```ruby
194
- # will generate a User::ACTIVE_STATES constant, User.active scope, and User#active? instance method
195
- state_alias :active, scope: true, constant: true do
196
- # ...
197
- end
198
- ```
199
-
200
- Passing `true` for the scope or constant will result in default naming conventions. You can pass your own names if you'd rather:
201
-
202
- ```ruby
203
- # will generate a User::THE_ACTIVE_STATES constant, User.the_active_ones scope, and User#active? instance method
204
- state_alias :active, scope: :the_active_ones, constant: :the_active_states do
205
- # ...
206
- end
207
- ```
208
-
209
- The `opposite` method also accepts the scope and constant options, but does not yield to a block since the state definitions are inheritenly tied to the ones described in the parent state_alias block.
210
-
211
- #### TODO
212
-
213
- * Allow for multiple variations of a transition (shift_down style - :third_gear => :second_gear, :second_gear => :first_gear)
214
- * Create adapters for different backends (not just ActiveRecord)
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env rake
2
- require 'rake'
3
- require "bundler/gem_tasks"
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec) do |spec|
7
- spec.pattern = 'spec/*_spec.rb'
8
- end
9
- task :default => :spec
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.1.0"
6
- gem "appraisal"
7
- gem "debug"
8
- gem "activerecord-nulldb-adapter"
9
- gem "rake"
10
- gem "rspec"
11
-
12
- gemspec path: "../"
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- stator (0.9.0.beta)
5
- activerecord
6
- activesupport
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (5.1.7)
12
- activesupport (= 5.1.7)
13
- activerecord (5.1.7)
14
- activemodel (= 5.1.7)
15
- activesupport (= 5.1.7)
16
- arel (~> 8.0)
17
- activerecord-nulldb-adapter (0.4.0)
18
- activerecord (>= 2.0.0)
19
- activesupport (5.1.7)
20
- concurrent-ruby (~> 1.0, >= 1.0.2)
21
- i18n (>= 0.7, < 2)
22
- minitest (~> 5.1)
23
- tzinfo (~> 1.1)
24
- appraisal (2.4.1)
25
- bundler
26
- rake
27
- thor (>= 0.14.0)
28
- arel (8.0.0)
29
- concurrent-ruby (1.1.10)
30
- debug (1.6.1)
31
- irb (>= 1.3.6)
32
- reline (>= 0.3.1)
33
- diff-lcs (1.5.0)
34
- i18n (1.12.0)
35
- concurrent-ruby (~> 1.0)
36
- io-console (0.5.11)
37
- irb (1.4.1)
38
- reline (>= 0.3.0)
39
- minitest (5.16.2)
40
- rake (13.0.6)
41
- reline (0.3.1)
42
- io-console (~> 0.5)
43
- rspec (3.11.0)
44
- rspec-core (~> 3.11.0)
45
- rspec-expectations (~> 3.11.0)
46
- rspec-mocks (~> 3.11.0)
47
- rspec-core (3.11.0)
48
- rspec-support (~> 3.11.0)
49
- rspec-expectations (3.11.0)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.11.0)
52
- rspec-mocks (3.11.1)
53
- diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.11.0)
55
- rspec-support (3.11.0)
56
- thor (1.2.1)
57
- thread_safe (0.3.6)
58
- tzinfo (1.2.10)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord (~> 5.1.0)
66
- activerecord-nulldb-adapter
67
- appraisal
68
- debug
69
- rake
70
- rspec
71
- stator!
72
-
73
- BUNDLED WITH
74
- 2.3.16
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.2.0"
6
- gem "appraisal"
7
- gem "debug"
8
- gem "activerecord-nulldb-adapter"
9
- gem "rake"
10
- gem "rspec"
11
-
12
- gemspec path: "../"
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- stator (0.9.0.beta)
5
- activerecord
6
- activesupport
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (5.2.8.1)
12
- activesupport (= 5.2.8.1)
13
- activerecord (5.2.8.1)
14
- activemodel (= 5.2.8.1)
15
- activesupport (= 5.2.8.1)
16
- arel (>= 9.0)
17
- activerecord-nulldb-adapter (0.8.0)
18
- activerecord (>= 5.2.0, < 7.1)
19
- activesupport (5.2.8.1)
20
- concurrent-ruby (~> 1.0, >= 1.0.2)
21
- i18n (>= 0.7, < 2)
22
- minitest (~> 5.1)
23
- tzinfo (~> 1.1)
24
- appraisal (2.4.1)
25
- bundler
26
- rake
27
- thor (>= 0.14.0)
28
- arel (9.0.0)
29
- concurrent-ruby (1.1.10)
30
- debug (1.6.1)
31
- irb (>= 1.3.6)
32
- reline (>= 0.3.1)
33
- diff-lcs (1.5.0)
34
- i18n (1.12.0)
35
- concurrent-ruby (~> 1.0)
36
- io-console (0.5.11)
37
- irb (1.4.1)
38
- reline (>= 0.3.0)
39
- minitest (5.16.2)
40
- rake (13.0.6)
41
- reline (0.3.1)
42
- io-console (~> 0.5)
43
- rspec (3.11.0)
44
- rspec-core (~> 3.11.0)
45
- rspec-expectations (~> 3.11.0)
46
- rspec-mocks (~> 3.11.0)
47
- rspec-core (3.11.0)
48
- rspec-support (~> 3.11.0)
49
- rspec-expectations (3.11.0)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.11.0)
52
- rspec-mocks (3.11.1)
53
- diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.11.0)
55
- rspec-support (3.11.0)
56
- thor (1.2.1)
57
- thread_safe (0.3.6)
58
- tzinfo (1.2.10)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord (~> 5.2.0)
66
- activerecord-nulldb-adapter
67
- appraisal
68
- debug
69
- rake
70
- rspec
71
- stator!
72
-
73
- BUNDLED WITH
74
- 2.3.16
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.0.0"
6
- gem "appraisal"
7
- gem "debug"
8
- gem "activerecord-nulldb-adapter"
9
- gem "rake"
10
- gem "rspec"
11
-
12
- gemspec path: "../"
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- stator (0.9.0.beta)
5
- activerecord
6
- activesupport
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (5.0.7.2)
12
- activesupport (= 5.0.7.2)
13
- activerecord (5.0.7.2)
14
- activemodel (= 5.0.7.2)
15
- activesupport (= 5.0.7.2)
16
- arel (~> 7.0)
17
- activerecord-nulldb-adapter (0.4.0)
18
- activerecord (>= 2.0.0)
19
- activesupport (5.0.7.2)
20
- concurrent-ruby (~> 1.0, >= 1.0.2)
21
- i18n (>= 0.7, < 2)
22
- minitest (~> 5.1)
23
- tzinfo (~> 1.1)
24
- appraisal (2.4.1)
25
- bundler
26
- rake
27
- thor (>= 0.14.0)
28
- arel (7.1.4)
29
- concurrent-ruby (1.1.10)
30
- debug (1.6.1)
31
- irb (>= 1.3.6)
32
- reline (>= 0.3.1)
33
- diff-lcs (1.5.0)
34
- i18n (1.12.0)
35
- concurrent-ruby (~> 1.0)
36
- io-console (0.5.11)
37
- irb (1.4.1)
38
- reline (>= 0.3.0)
39
- minitest (5.16.2)
40
- rake (13.0.6)
41
- reline (0.3.1)
42
- io-console (~> 0.5)
43
- rspec (3.11.0)
44
- rspec-core (~> 3.11.0)
45
- rspec-expectations (~> 3.11.0)
46
- rspec-mocks (~> 3.11.0)
47
- rspec-core (3.11.0)
48
- rspec-support (~> 3.11.0)
49
- rspec-expectations (3.11.0)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.11.0)
52
- rspec-mocks (3.11.1)
53
- diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.11.0)
55
- rspec-support (3.11.0)
56
- thor (1.2.1)
57
- thread_safe (0.3.6)
58
- tzinfo (1.2.10)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord (~> 5.0.0)
66
- activerecord-nulldb-adapter
67
- appraisal
68
- debug
69
- rake
70
- rspec
71
- stator!
72
-
73
- BUNDLED WITH
74
- 2.3.16
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 6.0.0"
6
- gem "appraisal"
7
- gem "debug"
8
- gem "activerecord-nulldb-adapter"
9
- gem "rake"
10
- gem "rspec"
11
-
12
- gemspec path: "../"
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- stator (0.9.0.beta)
5
- activerecord
6
- activesupport
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (6.0.5.1)
12
- activesupport (= 6.0.5.1)
13
- activerecord (6.0.5.1)
14
- activemodel (= 6.0.5.1)
15
- activesupport (= 6.0.5.1)
16
- activerecord-nulldb-adapter (0.8.0)
17
- activerecord (>= 5.2.0, < 7.1)
18
- activesupport (6.0.5.1)
19
- concurrent-ruby (~> 1.0, >= 1.0.2)
20
- i18n (>= 0.7, < 2)
21
- minitest (~> 5.1)
22
- tzinfo (~> 1.1)
23
- zeitwerk (~> 2.2, >= 2.2.2)
24
- appraisal (2.4.1)
25
- bundler
26
- rake
27
- thor (>= 0.14.0)
28
- concurrent-ruby (1.1.10)
29
- debug (1.6.1)
30
- irb (>= 1.3.6)
31
- reline (>= 0.3.1)
32
- diff-lcs (1.5.0)
33
- i18n (1.12.0)
34
- concurrent-ruby (~> 1.0)
35
- io-console (0.5.11)
36
- irb (1.4.1)
37
- reline (>= 0.3.0)
38
- minitest (5.16.2)
39
- rake (13.0.6)
40
- reline (0.3.1)
41
- io-console (~> 0.5)
42
- rspec (3.11.0)
43
- rspec-core (~> 3.11.0)
44
- rspec-expectations (~> 3.11.0)
45
- rspec-mocks (~> 3.11.0)
46
- rspec-core (3.11.0)
47
- rspec-support (~> 3.11.0)
48
- rspec-expectations (3.11.0)
49
- diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.11.0)
51
- rspec-mocks (3.11.1)
52
- diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.11.0)
54
- rspec-support (3.11.0)
55
- thor (1.2.1)
56
- thread_safe (0.3.6)
57
- tzinfo (1.2.10)
58
- thread_safe (~> 0.1)
59
- zeitwerk (2.6.0)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord (~> 6.0.0)
66
- activerecord-nulldb-adapter
67
- appraisal
68
- debug
69
- rake
70
- rspec
71
- stator!
72
-
73
- BUNDLED WITH
74
- 2.3.16
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 6.1.0"
6
- gem "appraisal"
7
- gem "debug"
8
- gem "activerecord-nulldb-adapter"
9
- gem "rake"
10
- gem "rspec"
11
-
12
- gemspec path: "../"