aasm 5.1.0 → 5.3.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/build.yml +100 -0
- data/Appraisals +18 -34
- data/CHANGELOG.md +28 -0
- data/Gemfile +3 -2
- data/README.md +93 -15
- data/aasm.gemspec +1 -1
- data/gemfiles/norails.gemfile +1 -0
- data/gemfiles/rails_4.2.gemfile +2 -2
- data/gemfiles/rails_4.2_mongoid_5.gemfile +2 -2
- data/gemfiles/rails_4.2_nobrainer.gemfile +2 -1
- data/gemfiles/rails_5.2.gemfile +2 -2
- data/gemfiles/rails_6.0.gemfile +14 -0
- data/gemfiles/rails_6.1.gemfile +14 -0
- data/gemfiles/rails_7.0.gemfile +14 -0
- data/lib/aasm/base.rb +44 -12
- data/lib/aasm/configuration.rb +3 -0
- data/lib/aasm/core/event.rb +12 -6
- data/lib/aasm/core/state.rb +6 -5
- data/lib/aasm/core/transition.rb +1 -1
- data/lib/aasm/dsl_helper.rb +24 -22
- data/lib/aasm/instance_base.rb +14 -4
- data/lib/aasm/localizer.rb +13 -3
- data/lib/aasm/persistence/active_record_persistence.rb +18 -13
- data/lib/aasm/persistence/base.rb +13 -2
- data/lib/aasm/persistence/orm.rb +1 -1
- data/lib/aasm/version.rb +1 -1
- data/lib/aasm.rb +0 -2
- data/lib/generators/active_record/templates/migration.rb +1 -1
- data/spec/database.rb +9 -11
- data/spec/en.yml +0 -3
- data/spec/{en_deprecated_style.yml → localizer_test_model_deprecated_style.yml} +6 -3
- data/spec/localizer_test_model_new_style.yml +11 -0
- data/spec/models/active_record/localizer_test_model.rb +11 -3
- data/spec/models/active_record/namespaced.rb +16 -0
- data/spec/models/active_record/timestamp_example.rb +16 -0
- data/spec/models/default_state.rb +1 -1
- data/spec/models/event_with_keyword_arguments.rb +16 -0
- data/spec/models/mongoid/timestamp_example_mongoid.rb +20 -0
- data/spec/models/timestamps_example.rb +19 -0
- data/spec/models/timestamps_with_named_machine_example.rb +13 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/spec_helpers/dynamoid.rb +5 -1
- data/spec/unit/api_spec.rb +4 -0
- data/spec/unit/callbacks_spec.rb +34 -4
- data/spec/unit/complex_example_spec.rb +8 -0
- data/spec/unit/event_with_keyword_arguments_spec.rb +10 -0
- data/spec/unit/inspection_multiple_spec.rb +9 -5
- data/spec/unit/inspection_spec.rb +7 -3
- data/spec/unit/localizer_spec.rb +49 -18
- data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +17 -0
- data/spec/unit/persistence/active_record_persistence_spec.rb +12 -0
- data/spec/unit/persistence/mongoid_persistence_spec.rb +12 -0
- data/spec/unit/state_spec.rb +21 -5
- data/spec/unit/timestamps_spec.rb +32 -0
- data/test/minitest_helper.rb +5 -1
- metadata +28 -16
- data/.travis.yml +0 -93
- data/gemfiles/rails_5.0.gemfile +0 -14
- data/gemfiles/rails_5.0_nobrainer.gemfile +0 -9
- data/gemfiles/rails_5.1.gemfile +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 442f7c145e97a545e9dd1cd5ecab268177b93deb0b258ab381107f1207fe9654
|
4
|
+
data.tar.gz: 1d32640b0bfab501acc40b10f7d21be342944ed133086d44ccb924f03485f3b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be33b17c558b289c012f25ccbed984cd3b2859e14a5120bf240020eb2d83c2645834784e5bc50dac0e5a3f161f13f3d85c2a29dcefcce694be395b604676ef32
|
7
|
+
data.tar.gz: 87668c8a48a9cf0335a4359970e868758a25398e2af8fb025ab9dd39db2a89147f0fad25fee9c11e1da9522fbeca6595f5363318b8baf2b7625ee1b88f3d8b80
|
@@ -0,0 +1,100 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
|
10
|
+
continue-on-error: ${{ matrix.allow_failure || false }}
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
os: [ubuntu-20.04]
|
15
|
+
ruby: ['3.0', 2.7, 2.6, jruby-9.1.17.0, truffleruby]
|
16
|
+
gemfile: [norails, rails_4.2, rails_4.2_mongoid_5, rails_5.2, rails_6.1]
|
17
|
+
redis-version: [6]
|
18
|
+
mongodb-version: [5]
|
19
|
+
include:
|
20
|
+
- ruby: '3.0'
|
21
|
+
gemfile: rails_6.1
|
22
|
+
os: ubuntu-20.04
|
23
|
+
redis-version: 6
|
24
|
+
mongodb-version: 5
|
25
|
+
- ruby: 3.1
|
26
|
+
gemfile: rails_7.0
|
27
|
+
os: ubuntu-20.04
|
28
|
+
redis-version: 6
|
29
|
+
mongodb-version: 5
|
30
|
+
exclude:
|
31
|
+
- ruby: '3.0'
|
32
|
+
gemfile: rails_5.2
|
33
|
+
- ruby: '3.0'
|
34
|
+
gemfile: rails_4.2
|
35
|
+
- ruby: '3.0'
|
36
|
+
gemfile: rails_4.2_mongoid_5
|
37
|
+
- ruby: 2.7
|
38
|
+
gemfile: rails_5.2
|
39
|
+
- ruby: 2.7
|
40
|
+
gemfile: rails_4.2
|
41
|
+
- ruby: 2.7
|
42
|
+
gemfile: rails_4.2_mongoid_5
|
43
|
+
- ruby: 2.6
|
44
|
+
gemfile: rails_4.2_mongoid_5
|
45
|
+
- ruby: 2.6
|
46
|
+
gemfile: rails_4.2
|
47
|
+
- ruby: jruby-9.1.17.0
|
48
|
+
gemfile: norails
|
49
|
+
- ruby: jruby-9.1.17.0
|
50
|
+
gemfile: rails_5.2
|
51
|
+
- ruby: jruby-9.1.17.0
|
52
|
+
gemfile: rails_6.1
|
53
|
+
- ruby: truffleruby
|
54
|
+
gemfile: rails_4.2
|
55
|
+
- ruby: truffleruby
|
56
|
+
gemfile: rails_4.2_mongoid_5
|
57
|
+
- ruby: truffleruby
|
58
|
+
gemfile: rails_5.2
|
59
|
+
allow_failures:
|
60
|
+
- false
|
61
|
+
env:
|
62
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
63
|
+
ALLOW_FAILURES: "${{ matrix.allow_failures }}"
|
64
|
+
runs-on: ${{ matrix.os }}
|
65
|
+
|
66
|
+
steps:
|
67
|
+
- uses: actions/checkout@v2
|
68
|
+
- name: Install dependencies
|
69
|
+
run: |
|
70
|
+
mkdir /tmp/dynamodb
|
71
|
+
wget -O - https://s3-ap-southeast-1.amazonaws.com/dynamodb-local-singapore/dynamodb_local_latest.tar.gz | tar xz --directory /tmp/dynamodb
|
72
|
+
java -Djava.library.path=/tmp/dynamodb/DynamoDBLocal_lib -jar /tmp/dynamodb/DynamoDBLocal.jar -inMemory -delayTransientStatuses -port 30180 &
|
73
|
+
mongod --version
|
74
|
+
- uses: ruby/setup-ruby@v1
|
75
|
+
with:
|
76
|
+
ruby-version: ${{ matrix.ruby }}
|
77
|
+
bundler-cache: true
|
78
|
+
- name: Setup project
|
79
|
+
run: bundle install
|
80
|
+
- name: Start Redis
|
81
|
+
uses: supercharge/redis-github-action@1.2.0
|
82
|
+
with:
|
83
|
+
redis-version: ${{ matrix.redis-version }}
|
84
|
+
- name: Start MongoDB
|
85
|
+
uses: supercharge/mongodb-github-action@1.6.0
|
86
|
+
with:
|
87
|
+
mongodb-version: ${{ matrix.mongodb-version }}
|
88
|
+
# - name: Setup DynamoDB Local
|
89
|
+
# uses: rrainn/dynamodb-action@v2.0.0
|
90
|
+
# with:
|
91
|
+
# port: 8000
|
92
|
+
# cors: '*'
|
93
|
+
- name: Run specs
|
94
|
+
run: bundle exec rspec spec
|
95
|
+
- name: Run test
|
96
|
+
run: bundle exec rake test
|
97
|
+
- name: Upload coverage to Codecov
|
98
|
+
uses: codecov/codecov-action@v2
|
99
|
+
with:
|
100
|
+
fail_ci_if_error: false
|
data/Appraisals
CHANGED
@@ -1,62 +1,45 @@
|
|
1
1
|
appraise 'rails_4.2' do
|
2
2
|
gem 'nokogiri', '1.6.8.1', platforms: %i[ruby_19]
|
3
3
|
gem 'mime-types', '~> 2', platforms: %i[ruby_19 jruby]
|
4
|
-
gem '
|
4
|
+
gem 'sqlite3', '~> 1.3.5', platforms: :ruby
|
5
|
+
gem 'rails', '~> 4.2.11'
|
5
6
|
gem 'mongoid', '~> 4.0'
|
6
7
|
gem 'sequel'
|
7
8
|
gem 'dynamoid', '~> 1', platforms: :ruby
|
8
9
|
gem 'aws-sdk', '~> 2', platforms: :ruby
|
9
10
|
gem 'redis-objects'
|
10
11
|
gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
|
11
|
-
gem "after_commit_everywhere", "~>
|
12
|
-
end
|
13
|
-
|
14
|
-
appraise 'rails_4.2_nobrainer' do
|
15
|
-
gem 'rails', '4.2.5'
|
16
|
-
gem 'nobrainer', '~> 0.33.0'
|
12
|
+
gem "after_commit_everywhere", "~> 1.0"
|
17
13
|
end
|
18
14
|
|
19
15
|
appraise 'rails_4.2_mongoid_5' do
|
16
|
+
gem 'sqlite3', '~> 1.3.5', platforms: :ruby
|
20
17
|
gem 'mime-types', '~> 2', platforms: %i[ruby_19 jruby]
|
21
|
-
gem 'rails', '4.2.
|
18
|
+
gem 'rails', '~> 4.2.11'
|
22
19
|
gem 'mongoid', '~> 5.0'
|
23
20
|
gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
|
24
|
-
gem "after_commit_everywhere", "~>
|
25
|
-
end
|
26
|
-
|
27
|
-
appraise 'rails_5.0' do
|
28
|
-
gem 'rails', '5.0.0'
|
29
|
-
gem 'mongoid', '~> 6.0'
|
30
|
-
gem 'sequel'
|
31
|
-
gem 'dynamoid', '~> 1.3', platforms: :ruby
|
32
|
-
gem 'aws-sdk', '~> 2', platforms: :ruby
|
33
|
-
gem 'redis-objects'
|
34
|
-
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
21
|
+
gem "after_commit_everywhere", "~> 1.0"
|
35
22
|
end
|
36
23
|
|
37
|
-
appraise 'rails_5.
|
38
|
-
gem '
|
39
|
-
gem '
|
40
|
-
end
|
41
|
-
|
42
|
-
appraise 'rails_5.1' do
|
43
|
-
gem 'rails', '5.1'
|
24
|
+
appraise 'rails_5.2' do
|
25
|
+
gem 'sqlite3', '~> 1.3.5', platforms: :ruby
|
26
|
+
gem 'rails', '~> 5.2.4'
|
44
27
|
gem 'mongoid', '~>6.0'
|
45
28
|
gem 'sequel'
|
46
|
-
gem 'dynamoid', '~>
|
29
|
+
gem 'dynamoid', '~>2.2', platforms: :ruby
|
47
30
|
gem 'aws-sdk', '~>2', platforms: :ruby
|
48
31
|
gem 'redis-objects'
|
49
|
-
gem "after_commit_everywhere", "~>
|
32
|
+
gem "after_commit_everywhere", "~> 1.0"
|
50
33
|
end
|
51
34
|
|
52
|
-
appraise '
|
53
|
-
gem 'rails', '
|
54
|
-
gem 'mongoid', '~>
|
35
|
+
appraise 'rails_6.1' do
|
36
|
+
gem 'rails', '~> 6.1.4'
|
37
|
+
gem 'mongoid', '~>7.0', '>= 7.0.5'
|
55
38
|
gem 'sequel'
|
56
|
-
gem 'dynamoid', '~>
|
57
|
-
gem 'aws-sdk', '~>
|
39
|
+
gem 'dynamoid', '~>3.3', platforms: :ruby
|
40
|
+
gem 'aws-sdk-dynamodb', '~> 1'
|
58
41
|
gem 'redis-objects'
|
59
|
-
gem "after_commit_everywhere", "~>
|
42
|
+
gem "after_commit_everywhere", "~> 1.0"
|
60
43
|
end
|
61
44
|
|
62
45
|
appraise 'norails' do
|
@@ -64,4 +47,5 @@ appraise 'norails' do
|
|
64
47
|
gem 'rails', install_if: false
|
65
48
|
gem 'sequel'
|
66
49
|
gem 'redis-objects'
|
50
|
+
gem "after_commit_everywhere", install_if: false
|
67
51
|
end
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,34 @@
|
|
2
2
|
|
3
3
|
## unreleased
|
4
4
|
|
5
|
+
## 5.3.0
|
6
|
+
|
7
|
+
* Add Ruby 3.1 and Rails 7 to the CI matrix [#775](https://github.com/aasm/aasm/pull/775), thanks to [petergoldstein](https://github.com/petergoldstein)
|
8
|
+
* Fixed an error in Ruby 3 when specifying a method that takes keyword arguments, such as event's before hook [#777](https://github.com/aasm/aasm/pull/777), thanks to [pocari](https://github.com/pocari)
|
9
|
+
* Fix multi-threading bug not firing success callbacks [#778](https://github.com/aasm/aasm/pull/778), thanks to [guewen](https://github.com/guewen)
|
10
|
+
* Raise AASM::UndefinedState when calling fire or fire! with undefined event names [#753](https://github.com/aasm/aasm/pull/753), thanks to [danielvdao](https://github.com/danielvdao)
|
11
|
+
* Fixing Readme typos [#745](https://github.com/aasm/aasm/pull/745) [#772](https://github.com/aasm/aasm/pull/772) [#774](https://github.com/aasm/aasm/pull/774) [#781](https://github.com/aasm/aasm/pull/781), thanks to [jaredsmithse](https://github.com/jaredsmithse) [jcat4](https://github.com/jcat4) [ChandanChainani](https://github.com/ChandanChainani) [TessHuelskamp](https://github.com/TessHuelskamp)
|
12
|
+
* Add github actions config [#750](https://github.com/aasm/aasm/pull/750), thanks to [aka47](https://github.com/aka47)
|
13
|
+
* Test against for Rails 6.0 and improve ci [#719](https://github.com/aasm/aasm/pull/719), thanks to [yujideveloper](https://github.com/yujideveloper)
|
14
|
+
* Fix migration class name to work with zeitwerk [#720](https://github.com/aasm/aasm/pull/720), thanks to [rwegrzyniak](https://github.com/rwegrzyniak)
|
15
|
+
## 5.2.0
|
16
|
+
|
17
|
+
* fix: timestamp will work with named machine [#739](https://github.com/aasm/aasm/pull/739), thanks to [RolandStuder](https://github.com/RolandStuder)
|
18
|
+
* Create namespaced scopes in PR [#735](https://github.com/aasm/aasm/pull/735), thanks to [caiohsramos](https://github.com/caiohsramos)
|
19
|
+
* Fix multiple state machines example per class on README in PR [#732](https://github.com/aasm/aasm/pull/732), thanks to [RodrigoVitiello](https://github.com/RodrigoVitiello)
|
20
|
+
* Update version in recommendation to add after_commit_everywhere in PR [#729](https://github.com/aasm/aasm/pull/729), thanks to [Envek](https://github.com/Envek)
|
21
|
+
* Fix i18n Event translations failing [#721](https://github.com/aasm/aasm/issues/721) in PR [#723](https://github.com/aasm/aasm/pull/723), thanks to [the-spectator](https://github.com/the-spectator)
|
22
|
+
* Add documentation to the Readme about how parameters are handled in AASM events in PR [#722](https://github.com/aasm/aasm/pull/722), thanks to [dstuebe](https://github.com/dstuebe)
|
23
|
+
* Fix human_state cached across locales [#709](https://github.com/aasm/aasm/issues/709) in PR [716](https://github.com/aasm/aasm/pull/716), thanks to [the-spectator](https://github.com/the-spectator)
|
24
|
+
* Relocate DslHelper from root namespace to under AASM namespace in PR [#711](https://github.com/aasm/aasm/pull/711) thank to [yujideveloper ](https://github.com/yujideveloper )
|
25
|
+
* Document how to define transitions from any state in in PR [#699](https://github.com/aasm/aasm/pull/699) thanks to [hedgesky](https://github.com/hedgesky)
|
26
|
+
* Add simple option for auto-generated timestamps in PR [#677](https://github.com/aasm/aasm/pull/677), thanks to [jaynetics](https://github.com/jaynetics)
|
27
|
+
## 5.1.1
|
28
|
+
|
29
|
+
* Fix Depreciation message for after_commit_everywhere [#695](https://github.com/aasm/aasm/issues/695) in PR [#696](https://github.com/aasm/aasm/pull/696)
|
30
|
+
* Fix human_state to use display option [#684](https://github.com/aasm/aasm/issues/684) in PR [#697](https://github.com/aasm/aasm/pull/697)
|
31
|
+
* Remove support for ruby 2.3
|
32
|
+
|
5
33
|
## 5.1.0
|
6
34
|
|
7
35
|
* Fix after_commit in nested transactions [#536](https://github.com/aasm/aasm/issues/536) without explicit AR dependency in PR [#668](https://github.com/aasm/aasm/pull/668), thanks to [stokarenko](https://github.com/stokarenko)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
- [Extending AASM](#extending-aasm)
|
21
21
|
- [ActiveRecord](#activerecord)
|
22
22
|
- [Bang events](#bang-events)
|
23
|
+
- [Timestamps](#timestamps)
|
23
24
|
- [ActiveRecord enums](#activerecord-enums)
|
24
25
|
- [Sequel](#sequel)
|
25
26
|
- [Dynamoid](#dynamoid)
|
@@ -212,15 +213,28 @@ class LogRunTime
|
|
212
213
|
end
|
213
214
|
```
|
214
215
|
|
215
|
-
|
216
|
+
#### Parameters
|
217
|
+
You can pass parameters to events:
|
216
218
|
|
217
219
|
```ruby
|
218
220
|
job = Job.new
|
219
221
|
job.run(:defragmentation)
|
220
222
|
```
|
221
223
|
|
222
|
-
In this case
|
224
|
+
All guards and after callbacks will receive these parameters. In this case `set_process` would be called with
|
225
|
+
`:defragmentation` argument.
|
223
226
|
|
227
|
+
If the first argument to the event is a state (e.g. `:running` or `:finished`), the first argument is consumed and
|
228
|
+
the state machine will attempt to transition to that state. Add comma separated parameter for guards and callbacks
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
job = Job.new
|
232
|
+
job.run(:running, :defragmentation)
|
233
|
+
```
|
234
|
+
In this case `set_process` won't be called, job will transition to running state and callback will receive
|
235
|
+
`:defragmentation` as parameter
|
236
|
+
|
237
|
+
#### Error Handling
|
224
238
|
In case of an error during the event processing the error is rescued and passed to `:error`
|
225
239
|
callback, which can handle it or re-raise it for further propagation.
|
226
240
|
|
@@ -307,7 +321,7 @@ and then
|
|
307
321
|
Let's assume you want to allow particular transitions only if a defined condition is
|
308
322
|
given. For this you can set up a guard per transition, which will run before actually
|
309
323
|
running the transition. If the guard returns `false` the transition will be
|
310
|
-
denied (raising `AASM::InvalidTransition`
|
324
|
+
denied (raising `AASM::InvalidTransition`):
|
311
325
|
|
312
326
|
```ruby
|
313
327
|
class Cleaner
|
@@ -350,7 +364,7 @@ job.clean # => raises AASM::InvalidTransition
|
|
350
364
|
job.may_clean_if_needed? # => true
|
351
365
|
job.clean_if_needed! # idle
|
352
366
|
|
353
|
-
job.clean_if_dirty(:clean) # =>
|
367
|
+
job.clean_if_dirty(:clean) # => raises AASM::InvalidTransition
|
354
368
|
job.clean_if_dirty(:dirty) # => true
|
355
369
|
```
|
356
370
|
|
@@ -386,7 +400,7 @@ If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as we
|
|
386
400
|
end
|
387
401
|
```
|
388
402
|
|
389
|
-
You can invoke a Class instead a method
|
403
|
+
You can invoke a Class instead of a method if the Class responds to `call`
|
390
404
|
|
391
405
|
```ruby
|
392
406
|
event :sleep do
|
@@ -434,6 +448,33 @@ job.stage1_completed
|
|
434
448
|
job.aasm.current_state # stage3
|
435
449
|
```
|
436
450
|
|
451
|
+
You can define transition from any defined state by omitting `from`:
|
452
|
+
|
453
|
+
```ruby
|
454
|
+
event :abort do
|
455
|
+
transitions to: :aborted
|
456
|
+
end
|
457
|
+
```
|
458
|
+
|
459
|
+
### Display name for state
|
460
|
+
|
461
|
+
You can define display name for state using :display option
|
462
|
+
|
463
|
+
```ruby
|
464
|
+
class Job
|
465
|
+
include AASM
|
466
|
+
|
467
|
+
aasm do
|
468
|
+
state :stage1, initial: true, display: 'First Stage'
|
469
|
+
state :stage2
|
470
|
+
state :stage3
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
job = Job.new
|
475
|
+
job.aasm.human_state
|
476
|
+
|
477
|
+
```
|
437
478
|
|
438
479
|
### Multiple state machines per class
|
439
480
|
|
@@ -476,13 +517,13 @@ simple = SimpleMultipleExample.new
|
|
476
517
|
|
477
518
|
simple.aasm(:move).current_state
|
478
519
|
# => :standing
|
479
|
-
simple.aasm(:work).
|
520
|
+
simple.aasm(:work).current_state
|
480
521
|
# => :sleeping
|
481
522
|
|
482
523
|
simple.start
|
483
524
|
simple.aasm(:move).current_state
|
484
525
|
# => :standing
|
485
|
-
simple.aasm(:work).
|
526
|
+
simple.aasm(:work).current_state
|
486
527
|
# => :processing
|
487
528
|
|
488
529
|
```
|
@@ -679,7 +720,7 @@ end
|
|
679
720
|
AASM comes with support for ActiveRecord and allows automatic persisting of the object's
|
680
721
|
state in the database.
|
681
722
|
|
682
|
-
Add `gem 'after_commit_everywhere', '~>
|
723
|
+
Add `gem 'after_commit_everywhere', '~> 1.0'` to your Gemfile.
|
683
724
|
|
684
725
|
```ruby
|
685
726
|
class Job < ActiveRecord::Base
|
@@ -717,7 +758,7 @@ job.aasm.fire!(:run) # saved
|
|
717
758
|
|
718
759
|
Saving includes running all validations on the `Job` class. If
|
719
760
|
`whiny_persistence` flag is set to `true`, exception is raised in case of
|
720
|
-
failure. If `whiny_persistence` flag is set to false
|
761
|
+
failure. If `whiny_persistence` flag is set to `false`, methods with a bang return
|
721
762
|
`true` if the state transition is successful or `false` if an error occurs.
|
722
763
|
|
723
764
|
If you want make sure the state gets saved without running validations (and
|
@@ -745,7 +786,7 @@ class Job < ActiveRecord::Base
|
|
745
786
|
end
|
746
787
|
```
|
747
788
|
|
748
|
-
Also
|
789
|
+
Also, you can skip the validation at instance level with `some_event_name_without_validation!` method.
|
749
790
|
With this you have the flexibility of having validation for all your transitions by default and then skip it wherever required.
|
750
791
|
Please note that only state column will be updated as mentioned in the above example.
|
751
792
|
|
@@ -781,6 +822,37 @@ job.aasm_state = :running # => raises AASM::NoDirectAssignmentError
|
|
781
822
|
job.aasm_state # => 'sleeping'
|
782
823
|
```
|
783
824
|
|
825
|
+
### Timestamps
|
826
|
+
|
827
|
+
You can tell _AASM_ to try to write a timestamp whenever a new state is entered.
|
828
|
+
If `timestamps: true` is set, _AASM_ will look for a field named like the new state plus `_at` and try to fill it:
|
829
|
+
|
830
|
+
```ruby
|
831
|
+
class Job < ActiveRecord::Base
|
832
|
+
include AASM
|
833
|
+
|
834
|
+
aasm timestamps: true do
|
835
|
+
state :sleeping, initial: true
|
836
|
+
state :running
|
837
|
+
|
838
|
+
event :run do
|
839
|
+
transitions from: :sleeping, to: :running
|
840
|
+
end
|
841
|
+
end
|
842
|
+
end
|
843
|
+
```
|
844
|
+
|
845
|
+
resulting in this:
|
846
|
+
|
847
|
+
```ruby
|
848
|
+
job = Job.create
|
849
|
+
job.running_at # => nil
|
850
|
+
job.run!
|
851
|
+
job.running_at # => 2020-02-20 20:00:00
|
852
|
+
```
|
853
|
+
|
854
|
+
Missing timestamp fields are silently ignored, so it is not necessary to have setters (such as ActiveRecord columns) for *all* states when using this option.
|
855
|
+
|
784
856
|
#### ActiveRecord enums
|
785
857
|
|
786
858
|
You can use
|
@@ -988,7 +1060,7 @@ job.save! #notify_about_running_job is not run
|
|
988
1060
|
Please note that `:after_commit` AASM callbacks behaves around custom implementation
|
989
1061
|
of transaction pattern rather than a real-life DB transaction. This fact still causes
|
990
1062
|
the race conditions and redundant callback calls within nested transaction. In order
|
991
|
-
to fix that it's highly recommended to add `gem 'after_commit_everywhere', '~>
|
1063
|
+
to fix that it's highly recommended to add `gem 'after_commit_everywhere', '~> 1.0'`
|
992
1064
|
to your `Gemfile`.
|
993
1065
|
|
994
1066
|
If you want to encapsulate state changes within an own transaction, the behavior
|
@@ -1012,7 +1084,7 @@ end
|
|
1012
1084
|
|
1013
1085
|
which then leads to `transaction(requires_new: false)`, the Rails default.
|
1014
1086
|
|
1015
|
-
Additionally, if you do not want any of your
|
1087
|
+
Additionally, if you do not want any of your ActiveRecord actions to be
|
1016
1088
|
wrapped in a transaction, you can specify the `use_transactions` flag. This can
|
1017
1089
|
be useful if you want want to persist things to the database that happen as a
|
1018
1090
|
result of a transaction or callback, even when some error occurs. The
|
@@ -1032,7 +1104,7 @@ end
|
|
1032
1104
|
|
1033
1105
|
### Pessimistic Locking
|
1034
1106
|
|
1035
|
-
AASM supports [
|
1107
|
+
AASM supports [ActiveRecord pessimistic locking via `with_lock`](http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html#method-i-with_lock) for database persistence layers.
|
1036
1108
|
|
1037
1109
|
| Option | Purpose |
|
1038
1110
|
| ------ | ------- |
|
@@ -1088,7 +1160,7 @@ end
|
|
1088
1160
|
Whatever column name is used, make sure to add a migration to provide this column
|
1089
1161
|
(of type `string`).
|
1090
1162
|
Do not add default value for column at the database level. If you add default
|
1091
|
-
value in database then AASM callbacks on the initial state will not be fired upon
|
1163
|
+
value in database then AASM callbacks on the initial state will not be fired upon
|
1092
1164
|
instantiation of the model.
|
1093
1165
|
|
1094
1166
|
```ruby
|
@@ -1389,7 +1461,7 @@ After installing AASM you can run generator:
|
|
1389
1461
|
```
|
1390
1462
|
Replace NAME with the Model name, COLUMN_NAME is optional(default is 'aasm_state').
|
1391
1463
|
This will create a model (if one does not exist) and configure it with aasm block.
|
1392
|
-
For
|
1464
|
+
For ActiveRecord orm a migration file is added to add aasm state column to table.
|
1393
1465
|
|
1394
1466
|
### Docker
|
1395
1467
|
|
@@ -1419,6 +1491,12 @@ Feel free to
|
|
1419
1491
|
* [Anil Maurya](http://github.com/anilmaurya) (since 2016)
|
1420
1492
|
|
1421
1493
|
|
1494
|
+
|
1495
|
+
## Stargazers over time
|
1496
|
+
|
1497
|
+
[![Stargazers over time](https://starchart.cc/aasm/aasm.svg)](https://starchart.cc/aasm/aasm)
|
1498
|
+
|
1499
|
+
|
1422
1500
|
## [Contributing](CONTRIBUTING.md)
|
1423
1501
|
|
1424
1502
|
## Warranty ##
|
data/aasm.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'generator_spec'
|
25
25
|
s.add_development_dependency 'appraisal'
|
26
26
|
s.add_development_dependency "simplecov"
|
27
|
-
s.add_development_dependency "codecov", ">= 0.1.
|
27
|
+
s.add_development_dependency "codecov", ">= 0.1.21"
|
28
28
|
|
29
29
|
# debugging
|
30
30
|
# s.add_development_dependency 'debugger'
|
data/gemfiles/norails.gemfile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
6
|
-
gem "rails", "4.2.
|
6
|
+
gem "rails", "~> 4.2.11"
|
7
|
+
gem "after_commit_everywhere", "~> 1.0"
|
7
8
|
gem "nokogiri", "1.6.8.1", platforms: [:ruby_19]
|
8
9
|
gem "mime-types", "~> 2", platforms: [:ruby_19, :jruby]
|
9
10
|
gem "mongoid", "~> 4.0"
|
@@ -12,6 +13,5 @@ gem "dynamoid", "~> 1", platforms: :ruby
|
|
12
13
|
gem "aws-sdk", "~> 2", platforms: :ruby
|
13
14
|
gem "redis-objects"
|
14
15
|
gem "activerecord-jdbcsqlite3-adapter", "1.3.24", platforms: :jruby
|
15
|
-
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
16
16
|
|
17
17
|
gemspec path: "../"
|
@@ -3,10 +3,10 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
6
|
-
gem "rails", "4.2.
|
6
|
+
gem "rails", "~> 4.2.11"
|
7
|
+
gem "after_commit_everywhere", "~> 1.0"
|
7
8
|
gem "mime-types", "~> 2", platforms: [:ruby_19, :jruby]
|
8
9
|
gem "mongoid", "~> 5.0"
|
9
10
|
gem "activerecord-jdbcsqlite3-adapter", "1.3.24", platforms: :jruby
|
10
|
-
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
11
11
|
|
12
12
|
gemspec path: "../"
|
data/gemfiles/rails_5.2.gemfile
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
6
|
-
gem "rails", "5.2"
|
6
|
+
gem "rails", "~> 5.2.4"
|
7
|
+
gem "after_commit_everywhere", "~> 1.0"
|
7
8
|
gem "mongoid", "~>6.0"
|
8
9
|
gem "sequel"
|
9
10
|
gem "dynamoid", "~>2.2", platforms: :ruby
|
10
11
|
gem "aws-sdk", "~>2", platforms: :ruby
|
11
12
|
gem "redis-objects"
|
12
|
-
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
13
13
|
|
14
14
|
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", "~> 1.4", platforms: :ruby
|
6
|
+
gem "rails", "~> 6.0.3"
|
7
|
+
gem "after_commit_everywhere", "~> 1.0"
|
8
|
+
gem "mongoid", "~>7.0", ">= 7.0.5"
|
9
|
+
gem "sequel"
|
10
|
+
gem "dynamoid", "~>3.3", platforms: :ruby
|
11
|
+
gem "aws-sdk-dynamodb", "~> 1"
|
12
|
+
gem "redis-objects"
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", "~> 1.4", platforms: :ruby
|
6
|
+
gem "rails", "~> 6.1.4"
|
7
|
+
gem "after_commit_everywhere", "~> 1.0"
|
8
|
+
gem "mongoid", "~>7.0", ">= 7.0.5"
|
9
|
+
gem "sequel"
|
10
|
+
gem "dynamoid", "~>3.3", platforms: :ruby
|
11
|
+
gem "aws-sdk-dynamodb", "~> 1"
|
12
|
+
gem "redis-objects"
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", "~> 1.4", platforms: :ruby
|
6
|
+
gem "rails", "~> 7.0.1"
|
7
|
+
gem "after_commit_everywhere", "~> 1.0"
|
8
|
+
gem "mongoid", "~>7", ">= 7.3.4"
|
9
|
+
gem "sequel"
|
10
|
+
gem "dynamoid", "~>3.3", platforms: :ruby
|
11
|
+
gem "aws-sdk-dynamodb", "~> 1"
|
12
|
+
gem "redis-objects"
|
13
|
+
|
14
|
+
gemspec path: "../"
|