aasm 5.2.0 → 5.3.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.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +100 -0
- data/Appraisals +14 -30
- data/CHANGELOG.md +11 -0
- data/Gemfile +3 -2
- data/README.md +20 -14
- 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 +14 -1
- data/lib/aasm/core/event.rb +5 -4
- data/lib/aasm/instance_base.rb +13 -3
- data/lib/aasm/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -1
- data/spec/models/event_with_keyword_arguments.rb +16 -0
- data/spec/spec_helpers/dynamoid.rb +5 -1
- 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/test/minitest_helper.rb +5 -1
- metadata +10 -6
- data/.travis.yml +0 -82
- 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,7 +1,8 @@
|
|
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
|
@@ -11,50 +12,32 @@ appraise 'rails_4.2' do
|
|
11
12
|
gem "after_commit_everywhere", "~> 1.0"
|
12
13
|
end
|
13
14
|
|
14
|
-
appraise 'rails_4.2_nobrainer' do
|
15
|
-
gem 'rails', '4.2.5'
|
16
|
-
gem 'nobrainer', '~> 0.33.0'
|
17
|
-
end
|
18
|
-
|
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
21
|
gem "after_commit_everywhere", "~> 1.0"
|
25
22
|
end
|
26
23
|
|
27
|
-
appraise 'rails_5.
|
28
|
-
gem '
|
29
|
-
gem '
|
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", "~> 1.0"
|
35
|
-
end
|
36
|
-
|
37
|
-
appraise 'rails_5.0_nobrainer' do
|
38
|
-
gem 'rails', '5.0.0'
|
39
|
-
gem 'nobrainer', '~> 0.33.0'
|
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
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
42
|
gem "after_commit_everywhere", "~> 1.0"
|
60
43
|
end
|
@@ -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
@@ -1,6 +1,17 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
3
|
## unreleased
|
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)
|
4
15
|
## 5.2.0
|
5
16
|
|
6
17
|
* fix: timestamp will work with named machine [#739](https://github.com/aasm/aasm/pull/739), thanks to [RolandStuder](https://github.com/RolandStuder)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -221,18 +221,18 @@ You can pass parameters to events:
|
|
221
221
|
job.run(:defragmentation)
|
222
222
|
```
|
223
223
|
|
224
|
-
All guards and after callbacks will receive these parameters. In this case `set_process` would be called with
|
224
|
+
All guards and after callbacks will receive these parameters. In this case `set_process` would be called with
|
225
225
|
`:defragmentation` argument.
|
226
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
|
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
229
|
|
230
230
|
```ruby
|
231
231
|
job = Job.new
|
232
232
|
job.run(:running, :defragmentation)
|
233
233
|
```
|
234
|
-
In this case `set_process` won't be called, job will transition to running state and callback will receive
|
235
|
-
|
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
236
|
|
237
237
|
#### Error Handling
|
238
238
|
In case of an error during the event processing the error is rescued and passed to `:error`
|
@@ -321,7 +321,7 @@ and then
|
|
321
321
|
Let's assume you want to allow particular transitions only if a defined condition is
|
322
322
|
given. For this you can set up a guard per transition, which will run before actually
|
323
323
|
running the transition. If the guard returns `false` the transition will be
|
324
|
-
denied (raising `AASM::InvalidTransition`
|
324
|
+
denied (raising `AASM::InvalidTransition`):
|
325
325
|
|
326
326
|
```ruby
|
327
327
|
class Cleaner
|
@@ -364,7 +364,7 @@ job.clean # => raises AASM::InvalidTransition
|
|
364
364
|
job.may_clean_if_needed? # => true
|
365
365
|
job.clean_if_needed! # idle
|
366
366
|
|
367
|
-
job.clean_if_dirty(:clean) # =>
|
367
|
+
job.clean_if_dirty(:clean) # => raises AASM::InvalidTransition
|
368
368
|
job.clean_if_dirty(:dirty) # => true
|
369
369
|
```
|
370
370
|
|
@@ -400,7 +400,7 @@ If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as we
|
|
400
400
|
end
|
401
401
|
```
|
402
402
|
|
403
|
-
You can invoke a Class instead a method
|
403
|
+
You can invoke a Class instead of a method if the Class responds to `call`
|
404
404
|
|
405
405
|
```ruby
|
406
406
|
event :sleep do
|
@@ -758,7 +758,7 @@ job.aasm.fire!(:run) # saved
|
|
758
758
|
|
759
759
|
Saving includes running all validations on the `Job` class. If
|
760
760
|
`whiny_persistence` flag is set to `true`, exception is raised in case of
|
761
|
-
failure. If `whiny_persistence` flag is set to false
|
761
|
+
failure. If `whiny_persistence` flag is set to `false`, methods with a bang return
|
762
762
|
`true` if the state transition is successful or `false` if an error occurs.
|
763
763
|
|
764
764
|
If you want make sure the state gets saved without running validations (and
|
@@ -786,7 +786,7 @@ class Job < ActiveRecord::Base
|
|
786
786
|
end
|
787
787
|
```
|
788
788
|
|
789
|
-
Also
|
789
|
+
Also, you can skip the validation at instance level with `some_event_name_without_validation!` method.
|
790
790
|
With this you have the flexibility of having validation for all your transitions by default and then skip it wherever required.
|
791
791
|
Please note that only state column will be updated as mentioned in the above example.
|
792
792
|
|
@@ -1084,7 +1084,7 @@ end
|
|
1084
1084
|
|
1085
1085
|
which then leads to `transaction(requires_new: false)`, the Rails default.
|
1086
1086
|
|
1087
|
-
Additionally, if you do not want any of your
|
1087
|
+
Additionally, if you do not want any of your ActiveRecord actions to be
|
1088
1088
|
wrapped in a transaction, you can specify the `use_transactions` flag. This can
|
1089
1089
|
be useful if you want want to persist things to the database that happen as a
|
1090
1090
|
result of a transaction or callback, even when some error occurs. The
|
@@ -1104,7 +1104,7 @@ end
|
|
1104
1104
|
|
1105
1105
|
### Pessimistic Locking
|
1106
1106
|
|
1107
|
-
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.
|
1108
1108
|
|
1109
1109
|
| Option | Purpose |
|
1110
1110
|
| ------ | ------- |
|
@@ -1160,7 +1160,7 @@ end
|
|
1160
1160
|
Whatever column name is used, make sure to add a migration to provide this column
|
1161
1161
|
(of type `string`).
|
1162
1162
|
Do not add default value for column at the database level. If you add default
|
1163
|
-
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
|
1164
1164
|
instantiation of the model.
|
1165
1165
|
|
1166
1166
|
```ruby
|
@@ -1461,7 +1461,7 @@ After installing AASM you can run generator:
|
|
1461
1461
|
```
|
1462
1462
|
Replace NAME with the Model name, COLUMN_NAME is optional(default is 'aasm_state').
|
1463
1463
|
This will create a model (if one does not exist) and configure it with aasm block.
|
1464
|
-
For
|
1464
|
+
For ActiveRecord orm a migration file is added to add aasm state column to table.
|
1465
1465
|
|
1466
1466
|
### Docker
|
1467
1467
|
|
@@ -1491,6 +1491,12 @@ Feel free to
|
|
1491
1491
|
* [Anil Maurya](http://github.com/anilmaurya) (since 2016)
|
1492
1492
|
|
1493
1493
|
|
1494
|
+
|
1495
|
+
## Stargazers over time
|
1496
|
+
|
1497
|
+
[](https://starchart.cc/aasm/aasm)
|
1498
|
+
|
1499
|
+
|
1494
1500
|
## [Contributing](CONTRIBUTING.md)
|
1495
1501
|
|
1496
1502
|
## Warranty ##
|
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", "~> 1.0"
|
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", "~> 1.0"
|
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", "~> 1.0"
|
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: "../"
|
data/lib/aasm/base.rb
CHANGED
@@ -223,7 +223,20 @@ module AASM
|
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
|
-
klass.send(:define_method, method_name, method_definition)
|
226
|
+
klass.send(:define_method, method_name, method_definition).tap do |sym|
|
227
|
+
apply_ruby2_keyword(klass, sym)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def apply_ruby2_keyword(klass, sym)
|
232
|
+
if RUBY_VERSION >= '2.7.1'
|
233
|
+
if klass.instance_method(sym).parameters.find { |type, _| type.to_s.start_with?('rest') }
|
234
|
+
# If there is a place where you are receiving in *args, do ruby2_keywords.
|
235
|
+
klass.module_eval do
|
236
|
+
ruby2_keywords sym
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
227
240
|
end
|
228
241
|
|
229
242
|
def namespace?
|
data/lib/aasm/core/event.rb
CHANGED
@@ -10,7 +10,7 @@ module AASM::Core
|
|
10
10
|
@name = name
|
11
11
|
@state_machine = state_machine
|
12
12
|
@transitions = []
|
13
|
-
@valid_transitions = {}
|
13
|
+
@valid_transitions = Hash.new { |h, k| h[k] = {} }
|
14
14
|
@guards = Array(options[:guard] || options[:guards] || options[:if])
|
15
15
|
@unless = Array(options[:unless]) #TODO: This could use a better name
|
16
16
|
@default_display_name = name.to_s.gsub(/_/, ' ').capitalize
|
@@ -79,8 +79,9 @@ module AASM::Core
|
|
79
79
|
|
80
80
|
def fire_transition_callbacks(obj, *args)
|
81
81
|
from_state = obj.aasm(state_machine.name).current_state
|
82
|
-
transition = @valid_transitions[from_state]
|
83
|
-
|
82
|
+
transition = @valid_transitions[obj.object_id][from_state]
|
83
|
+
transition.invoke_success_callbacks(obj, *args) if transition
|
84
|
+
@valid_transitions.delete(obj.object_id)
|
84
85
|
end
|
85
86
|
|
86
87
|
def ==(event)
|
@@ -153,7 +154,7 @@ module AASM::Core
|
|
153
154
|
result = transition
|
154
155
|
else
|
155
156
|
result = to_state || Array(transition.to).first
|
156
|
-
Array(transition.to).each {|to| @valid_transitions[to] = transition }
|
157
|
+
Array(transition.to).each {|to| @valid_transitions[obj.object_id][to] = transition }
|
157
158
|
transition.execute(obj, *args)
|
158
159
|
end
|
159
160
|
|
data/lib/aasm/instance_base.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module AASM
|
2
2
|
class InstanceBase
|
3
|
-
|
4
3
|
attr_accessor :from_state, :to_state, :current_event
|
5
4
|
|
6
5
|
def initialize(instance, name=:default) # instance of the class including AASM, name of the state machine
|
@@ -115,12 +114,15 @@ module AASM
|
|
115
114
|
end
|
116
115
|
|
117
116
|
def fire(event_name, *args, &block)
|
117
|
+
event_exists?(event_name)
|
118
|
+
|
118
119
|
@instance.send(event_name, *args, &block)
|
119
120
|
end
|
120
121
|
|
121
122
|
def fire!(event_name, *args, &block)
|
122
|
-
event_name
|
123
|
-
|
123
|
+
event_exists?(event_name, true)
|
124
|
+
bang_event_name = "#{event_name}!".to_sym
|
125
|
+
@instance.send(bang_event_name, *args, &block)
|
124
126
|
end
|
125
127
|
|
126
128
|
def set_current_state_with_persistence(state)
|
@@ -129,5 +131,13 @@ module AASM
|
|
129
131
|
save_success
|
130
132
|
end
|
131
133
|
|
134
|
+
private
|
135
|
+
|
136
|
+
def event_exists?(event_name, bang = false)
|
137
|
+
event = @instance.class.aasm(@name).state_machine.events[event_name]
|
138
|
+
event_error = bang ? "#{event_name}!" : event_name
|
139
|
+
|
140
|
+
raise AASM::UndefinedState, "State :#{event_error} doesn't exist" if event.nil?
|
141
|
+
end
|
132
142
|
end
|
133
143
|
end
|
data/lib/aasm/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class AasmCreate<%= table_name.camelize %> < ActiveRecord::Migration[<%= ActiveRecord::VERSION::STRING.to_f %>]
|
2
2
|
def change
|
3
3
|
create_table(:<%= table_name %>) do |t|
|
4
4
|
t.string :<%= column_name %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class EventWithKeywordArguments
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
aasm do
|
5
|
+
state :open, :initial => true, :column => :status
|
6
|
+
state :closed
|
7
|
+
|
8
|
+
event :close do
|
9
|
+
before :_before_close
|
10
|
+
transitions from: :open, to: :closed
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def _before_close(key:)
|
15
|
+
end
|
16
|
+
end
|
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'dynamoid'
|
5
|
-
require 'aws-sdk-resources'
|
6
5
|
puts "dynamoid #{Dynamoid::VERSION} gem found, running Dynamoid specs \e[32m#{'✔'}\e[0m"
|
6
|
+
if Gem::Version.new(Dynamoid::VERSION) >= Gem::Version.new('3.0.0')
|
7
|
+
require 'aws-sdk-dynamodb'
|
8
|
+
else
|
9
|
+
require 'aws-sdk-resources'
|
10
|
+
end
|
7
11
|
|
8
12
|
ENV['ACCESS_KEY'] ||= 'abcd'
|
9
13
|
ENV['SECRET_KEY'] ||= '1234'
|
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -90,11 +90,9 @@ describe 'callbacks for the new DSL' do
|
|
90
90
|
expect(callback).to receive(:ensure_on_all_events).once.ordered
|
91
91
|
end
|
92
92
|
|
93
|
-
# puts "------- close!"
|
94
93
|
callback.close!
|
95
94
|
end
|
96
95
|
|
97
|
-
|
98
96
|
it "works fine after reload" do
|
99
97
|
show_debug_log = false
|
100
98
|
|
@@ -125,10 +123,43 @@ describe 'callbacks for the new DSL' do
|
|
125
123
|
expect(callback).to receive(:after_event).once.ordered
|
126
124
|
end
|
127
125
|
|
128
|
-
# puts "------- close!"
|
129
126
|
callback.close!
|
130
127
|
end
|
131
128
|
|
129
|
+
it 'does not run callbacks if firing an unknown event' do
|
130
|
+
show_debug_log = false
|
131
|
+
|
132
|
+
callback = Callbacks::Basic.new(:log => show_debug_log)
|
133
|
+
|
134
|
+
expect(callback).to_not receive(:before_all_events).ordered
|
135
|
+
expect(callback).to_not receive(:before_event).ordered
|
136
|
+
expect(callback).to_not receive(:event_guard).ordered
|
137
|
+
expect(callback).to_not receive(:transition_guard)
|
138
|
+
expect(callback).to_not receive(:before_exit_open)
|
139
|
+
expect(callback).to_not receive(:exit_open)
|
140
|
+
expect(callback).to_not receive(:after_all_transitions)
|
141
|
+
expect(callback).to_not receive(:after_transition)
|
142
|
+
expect(callback).to_not receive(:before_enter_closed)
|
143
|
+
expect(callback).to_not receive(:enter_closed)
|
144
|
+
expect(callback).to_not receive(:aasm_write_state)
|
145
|
+
expect(callback).to_not receive(:event_before_success)
|
146
|
+
expect(callback).to_not receive(:success_transition)
|
147
|
+
expect(callback).to_not receive(:after_exit_open)
|
148
|
+
expect(callback).to_not receive(:after_enter_closed)
|
149
|
+
expect(callback).to_not receive(:after_event)
|
150
|
+
expect(callback).to_not receive(:after_all_events)
|
151
|
+
expect(callback).to_not receive(:ensure_event).ordered
|
152
|
+
expect(callback).to_not receive(:ensure_on_all_events).ordered
|
153
|
+
|
154
|
+
expect {
|
155
|
+
callback.aasm.fire(:unknown)
|
156
|
+
}.to raise_error(AASM::UndefinedState, "State :unknown doesn't exist")
|
157
|
+
|
158
|
+
expect {
|
159
|
+
callback.aasm.fire!(:unknown)
|
160
|
+
}.to raise_error(AASM::UndefinedState, "State :unknown! doesn't exist")
|
161
|
+
end
|
162
|
+
|
132
163
|
it "does not run any state callback if the event guard fails" do
|
133
164
|
callback = Callbacks::Basic.new(:log => false)
|
134
165
|
callback.aasm.current_state
|
@@ -164,7 +195,6 @@ describe 'callbacks for the new DSL' do
|
|
164
195
|
callback = Callbacks::PrivateMethod.new(:log => show_debug_log)
|
165
196
|
callback.aasm.current_state
|
166
197
|
|
167
|
-
# puts "------- close!"
|
168
198
|
expect {
|
169
199
|
callback.close!
|
170
200
|
}.to_not raise_error
|
@@ -90,4 +90,12 @@ describe 'when being unsuspended' do
|
|
90
90
|
it "should not be able to fire unknown events" do
|
91
91
|
expect(auth.aasm.may_fire_event?(:unknown)).to be false
|
92
92
|
end
|
93
|
+
|
94
|
+
it "should raise AASM::UndefinedState when firing unknown events" do
|
95
|
+
expect { auth.aasm.fire(:unknown) }.to raise_error(AASM::UndefinedState, "State :unknown doesn't exist")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should raise AASM::UndefinedState when firing unknown bang events" do
|
99
|
+
expect { auth.aasm.fire!(:unknown) }.to raise_error(AASM::UndefinedState, "State :unknown! doesn't exist")
|
100
|
+
end
|
93
101
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EventWithKeywordArguments do
|
4
|
+
let(:example) { EventWithKeywordArguments.new }
|
5
|
+
describe 'enable keyword arguments' do
|
6
|
+
it 'should be executed correctly that method registered by "before hooks" for events with keyword arguments.' do
|
7
|
+
expect(example.close(key: 1)).to be_truthy
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/test/minitest_helper.rb
CHANGED
@@ -23,7 +23,11 @@ end
|
|
23
23
|
# Dynamoid initialization
|
24
24
|
begin
|
25
25
|
require 'dynamoid'
|
26
|
-
|
26
|
+
if Gem::Version.new(Dynamoid::VERSION) >= Gem::Version.new('3.0.0')
|
27
|
+
require 'aws-sdk-dynamodb'
|
28
|
+
else
|
29
|
+
require 'aws-sdk-resources'
|
30
|
+
end
|
27
31
|
|
28
32
|
ENV['ACCESS_KEY'] ||= 'abcd'
|
29
33
|
ENV['SECRET_KEY'] ||= '1234'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aasm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorsten Boettger
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -147,8 +147,8 @@ files:
|
|
147
147
|
- ".document"
|
148
148
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
149
149
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
150
|
+
- ".github/workflows/build.yml"
|
150
151
|
- ".gitignore"
|
151
|
-
- ".travis.yml"
|
152
152
|
- API
|
153
153
|
- Appraisals
|
154
154
|
- CHANGELOG.md
|
@@ -170,10 +170,10 @@ files:
|
|
170
170
|
- gemfiles/rails_4.2.gemfile
|
171
171
|
- gemfiles/rails_4.2_mongoid_5.gemfile
|
172
172
|
- gemfiles/rails_4.2_nobrainer.gemfile
|
173
|
-
- gemfiles/rails_5.0.gemfile
|
174
|
-
- gemfiles/rails_5.0_nobrainer.gemfile
|
175
|
-
- gemfiles/rails_5.1.gemfile
|
176
173
|
- gemfiles/rails_5.2.gemfile
|
174
|
+
- gemfiles/rails_6.0.gemfile
|
175
|
+
- gemfiles/rails_6.1.gemfile
|
176
|
+
- gemfiles/rails_7.0.gemfile
|
177
177
|
- lib/aasm.rb
|
178
178
|
- lib/aasm/aasm.rb
|
179
179
|
- lib/aasm/base.rb
|
@@ -282,6 +282,7 @@ files:
|
|
282
282
|
- spec/models/dynamoid/complex_dynamoid_example.rb
|
283
283
|
- spec/models/dynamoid/dynamoid_multiple.rb
|
284
284
|
- spec/models/dynamoid/dynamoid_simple.rb
|
285
|
+
- spec/models/event_with_keyword_arguments.rb
|
285
286
|
- spec/models/foo.rb
|
286
287
|
- spec/models/foo_callback_multiple.rb
|
287
288
|
- spec/models/guard_arguments_check.rb
|
@@ -362,6 +363,7 @@ files:
|
|
362
363
|
- spec/unit/event_multiple_spec.rb
|
363
364
|
- spec/unit/event_naming_spec.rb
|
364
365
|
- spec/unit/event_spec.rb
|
366
|
+
- spec/unit/event_with_keyword_arguments_spec.rb
|
365
367
|
- spec/unit/exception_spec.rb
|
366
368
|
- spec/unit/guard_arguments_check_spec.rb
|
367
369
|
- spec/unit/guard_multiple_spec.rb
|
@@ -493,6 +495,7 @@ test_files:
|
|
493
495
|
- spec/models/dynamoid/complex_dynamoid_example.rb
|
494
496
|
- spec/models/dynamoid/dynamoid_multiple.rb
|
495
497
|
- spec/models/dynamoid/dynamoid_simple.rb
|
498
|
+
- spec/models/event_with_keyword_arguments.rb
|
496
499
|
- spec/models/foo.rb
|
497
500
|
- spec/models/foo_callback_multiple.rb
|
498
501
|
- spec/models/guard_arguments_check.rb
|
@@ -573,6 +576,7 @@ test_files:
|
|
573
576
|
- spec/unit/event_multiple_spec.rb
|
574
577
|
- spec/unit/event_naming_spec.rb
|
575
578
|
- spec/unit/event_spec.rb
|
579
|
+
- spec/unit/event_with_keyword_arguments_spec.rb
|
576
580
|
- spec/unit/exception_spec.rb
|
577
581
|
- spec/unit/guard_arguments_check_spec.rb
|
578
582
|
- spec/unit/guard_multiple_spec.rb
|
data/.travis.yml
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
jdk:
|
6
|
-
- openjdk8
|
7
|
-
|
8
|
-
before_install:
|
9
|
-
- rvm list
|
10
|
-
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
11
|
-
- gem install bundler -v '1.16.1'
|
12
|
-
- bundle _1.16.1_ install
|
13
|
-
|
14
|
-
rvm:
|
15
|
-
- 2.5.0
|
16
|
-
- 2.6.5
|
17
|
-
- 2.7.0
|
18
|
-
- jruby-9.1.12.0
|
19
|
-
|
20
|
-
services:
|
21
|
-
- mongodb
|
22
|
-
- redis-server
|
23
|
-
|
24
|
-
#addons:
|
25
|
-
# rethinkdb: '2.3.4'
|
26
|
-
|
27
|
-
gemfile:
|
28
|
-
- gemfiles/norails.gemfile
|
29
|
-
- gemfiles/rails_4.2.gemfile
|
30
|
-
- gemfiles/rails_4.2_mongoid_5.gemfile
|
31
|
-
# - gemfiles/rails_4.2_nobrainer.gemfile
|
32
|
-
- gemfiles/rails_5.0.gemfile
|
33
|
-
# - gemfiles/rails_5.0_nobrainer.gemfile
|
34
|
-
- gemfiles/rails_5.1.gemfile
|
35
|
-
- gemfiles/rails_5.2.gemfile
|
36
|
-
|
37
|
-
before_script:
|
38
|
-
- mkdir /tmp/dynamodb
|
39
|
-
- wget -O - https://s3-ap-southeast-1.amazonaws.com/dynamodb-local-singapore/dynamodb_local_latest.tar.gz | tar xz --directory /tmp/dynamodb
|
40
|
-
- java -Djava.library.path=/tmp/dynamodb/DynamoDBLocal_lib -jar /tmp/dynamodb/DynamoDBLocal.jar -inMemory -delayTransientStatuses -port 30180 &
|
41
|
-
- mongod --version
|
42
|
-
|
43
|
-
script:
|
44
|
-
- bundle exec rspec spec
|
45
|
-
- bundle exec rake test
|
46
|
-
|
47
|
-
matrix:
|
48
|
-
exclude:
|
49
|
-
- rvm: 2.7.0
|
50
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
51
|
-
- rvm: 2.6.5
|
52
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
53
|
-
- rvm: 2.5.0
|
54
|
-
gemfile: gemfiles/rails_4.2.gemfile
|
55
|
-
- rvm: 2.6.5
|
56
|
-
gemfile: gemfiles/rails_4.2.gemfile
|
57
|
-
- rvm: 2.7.0
|
58
|
-
gemfile: gemfiles/rails_4.2.gemfile
|
59
|
-
- rvm: 2.5.0
|
60
|
-
gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
|
61
|
-
- rvm: 2.6.5
|
62
|
-
gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
|
63
|
-
- rvm: 2.7.0
|
64
|
-
gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
|
65
|
-
# - rvm: 2.5.0
|
66
|
-
# gemfile: gemfiles/rails_4.2_nobrainer.gemfile
|
67
|
-
- rvm: jruby-9.1.12.0
|
68
|
-
gemfile: gemfiles/norails.gemfile
|
69
|
-
- rvm: jruby-9.1.12.0
|
70
|
-
gemfile: gemfiles/rails_5.0.gemfile
|
71
|
-
- rvm: jruby-9.1.12.0
|
72
|
-
gemfile: gemfiles/rails_5.1.gemfile
|
73
|
-
- rvm: jruby-9.1.12.0
|
74
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
75
|
-
# - rvm: jruby-9.1.12.0
|
76
|
-
# gemfile: gemfiles/rails_4.2_nobrainer.gemfile
|
77
|
-
# - rvm: jruby-9.1.12.0
|
78
|
-
# gemfile: gemfiles/rails_5.0_nobrainer.gemfile
|
79
|
-
|
80
|
-
notifications:
|
81
|
-
slack:
|
82
|
-
secure: gpltVWntdKz0nSE6A5UvuX4qbN35uW51nsW+Ojgqm8Qsv8K240/NlZRYutFHr7GnJTe0rEEP2Oy3ZBnBtZKFn13RlTEAU/FCAxebr4H24rr29Ypwwp5xjiSE4MuoBEnroo4lw6ka3LsJnrY2PKRMiLJGsS0WsEPY4x8NUG/vyY8=
|
data/gemfiles/rails_5.0.gemfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
6
|
-
gem "rails", "5.0.0"
|
7
|
-
gem "mongoid", "~> 6.0"
|
8
|
-
gem "sequel"
|
9
|
-
gem "dynamoid", "~> 1.3", platforms: :ruby
|
10
|
-
gem "aws-sdk", "~> 2", platforms: :ruby
|
11
|
-
gem "redis-objects"
|
12
|
-
gem "after_commit_everywhere", "~> 1.0"
|
13
|
-
|
14
|
-
gemspec path: "../"
|
data/gemfiles/rails_5.1.gemfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
6
|
-
gem "rails", "5.1"
|
7
|
-
gem "mongoid", "~>6.0"
|
8
|
-
gem "sequel"
|
9
|
-
gem "dynamoid", "~> 1.3", platforms: :ruby
|
10
|
-
gem "aws-sdk", "~>2", platforms: :ruby
|
11
|
-
gem "redis-objects"
|
12
|
-
gem "after_commit_everywhere", "~> 1.0"
|
13
|
-
|
14
|
-
gemspec path: "../"
|