aasm 4.11.0 → 4.12.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -17
  3. data/Appraisals +44 -0
  4. data/CHANGELOG.md +24 -1
  5. data/CONTRIBUTING.md +24 -0
  6. data/Gemfile +4 -21
  7. data/README.md +81 -34
  8. data/Rakefile +6 -1
  9. data/TESTING.md +25 -0
  10. data/aasm.gemspec +5 -2
  11. data/gemfiles/rails_3.2.gemfile +13 -0
  12. data/gemfiles/rails_4.0.gemfile +8 -9
  13. data/gemfiles/rails_4.2.gemfile +9 -9
  14. data/gemfiles/rails_4.2_mongoid_5.gemfile +5 -9
  15. data/gemfiles/rails_5.0.gemfile +7 -16
  16. data/lib/aasm/aasm.rb +9 -3
  17. data/lib/aasm/base.rb +3 -1
  18. data/lib/aasm/configuration.rb +4 -0
  19. data/lib/aasm/core/event.rb +19 -9
  20. data/lib/aasm/core/state.rb +7 -0
  21. data/lib/aasm/core/transition.rb +9 -0
  22. data/lib/aasm/instance_base.rb +8 -8
  23. data/lib/aasm/persistence/active_record_persistence.rb +1 -1
  24. data/lib/aasm/persistence/base.rb +3 -3
  25. data/lib/aasm/persistence/mongoid_persistence.rb +48 -9
  26. data/lib/aasm/persistence.rb +0 -3
  27. data/lib/aasm/state_machine.rb +4 -2
  28. data/lib/aasm/state_machine_store.rb +5 -2
  29. data/lib/aasm/version.rb +1 -1
  30. data/lib/generators/active_record/aasm_generator.rb +1 -1
  31. data/lib/motion-aasm.rb +0 -1
  32. data/spec/en.yml +3 -0
  33. data/spec/generators/active_record_generator_spec.rb +42 -34
  34. data/spec/generators/mongoid_generator_spec.rb +4 -6
  35. data/spec/models/{invalid_persistor.rb → active_record/invalid_persistor.rb} +0 -2
  36. data/spec/models/{silent_persistor.rb → active_record/silent_persistor.rb} +0 -2
  37. data/spec/models/active_record/simple_new_dsl.rb +2 -2
  38. data/spec/models/{transactor.rb → active_record/transactor.rb} +0 -2
  39. data/spec/models/{validator.rb → active_record/validator.rb} +6 -3
  40. data/spec/models/callbacks/basic.rb +5 -2
  41. data/spec/models/guard_with_params.rb +24 -0
  42. data/spec/models/guard_with_params_multiple.rb +18 -0
  43. data/spec/models/mongoid/invalid_persistor_mongoid.rb +39 -0
  44. data/spec/models/mongoid/silent_persistor_mongoid.rb +39 -0
  45. data/spec/models/mongoid/simple_mongoid.rb +2 -2
  46. data/spec/models/mongoid/validator_mongoid.rb +100 -0
  47. data/spec/models/multi_transitioner.rb +10 -0
  48. data/spec/models/multiple_transitions_that_differ_only_by_guard.rb +31 -0
  49. data/spec/models/parametrised_event.rb +7 -0
  50. data/spec/models/simple_multiple_example.rb +12 -0
  51. data/spec/models/sub_class.rb +34 -0
  52. data/spec/spec_helper.rb +0 -33
  53. data/spec/spec_helpers/active_record.rb +7 -0
  54. data/spec/spec_helpers/dynamoid.rb +33 -0
  55. data/spec/spec_helpers/mongoid.rb +7 -0
  56. data/spec/spec_helpers/redis.rb +7 -0
  57. data/spec/spec_helpers/remove_warnings.rb +1 -0
  58. data/spec/spec_helpers/sequel.rb +7 -0
  59. data/spec/unit/api_spec.rb +76 -73
  60. data/spec/unit/callbacks_spec.rb +5 -0
  61. data/spec/unit/event_spec.rb +12 -0
  62. data/spec/unit/guard_with_params_multiple_spec.rb +10 -0
  63. data/spec/unit/guard_with_params_spec.rb +14 -0
  64. data/spec/unit/inspection_spec.rb +5 -0
  65. data/spec/unit/localizer_spec.rb +55 -53
  66. data/spec/unit/multiple_transitions_that_differ_only_by_guard_spec.rb +14 -0
  67. data/spec/unit/override_warning_spec.rb +8 -0
  68. data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +452 -445
  69. data/spec/unit/persistence/active_record_persistence_spec.rb +523 -490
  70. data/spec/unit/persistence/dynamoid_persistence_multiple_spec.rb +4 -9
  71. data/spec/unit/persistence/dynamoid_persistence_spec.rb +4 -9
  72. data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +87 -10
  73. data/spec/unit/persistence/mongoid_persistence_spec.rb +89 -10
  74. data/spec/unit/persistence/redis_persistence_spec.rb +3 -7
  75. data/spec/unit/persistence/sequel_persistence_multiple_spec.rb +4 -9
  76. data/spec/unit/persistence/sequel_persistence_spec.rb +4 -9
  77. data/spec/unit/simple_multiple_example_spec.rb +28 -0
  78. data/spec/unit/subclassing_multiple_spec.rb +37 -2
  79. data/spec/unit/subclassing_spec.rb +17 -2
  80. metadata +77 -32
  81. data/gemfiles/rails_3.2_stable.gemfile +0 -15
  82. data/gemfiles/rails_4.0_mongo_mapper.gemfile +0 -17
  83. data/gemfiles/rails_4.2_mongo_mapper.gemfile +0 -18
  84. data/lib/aasm/persistence/mongo_mapper_persistence.rb +0 -163
  85. data/spec/models/mongo_mapper/complex_mongo_mapper_example.rb +0 -37
  86. data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +0 -21
  87. data/spec/models/mongo_mapper/simple_mongo_mapper.rb +0 -23
  88. data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +0 -25
  89. data/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +0 -146
  90. data/spec/unit/persistence/mongo_mapper_persistence_spec.rb +0 -93
  91. /data/spec/models/{worker.rb → active_record/worker.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c0f9cf1b1303a1269e84ada192ce2d56b2ad29b
4
- data.tar.gz: 8ad1ec953454bb5fbf113d9a47494fae24238744
3
+ metadata.gz: fedd52d9c93d911e324c5c3594910d7fb7b33db2
4
+ data.tar.gz: a0334890f17ce24960567a8f95e0cafd03375a9f
5
5
  SHA512:
6
- metadata.gz: 29373b642050f83f1d44a5241857b9e75b0aa1dd4b224b161f057acdde5595bf79e57554229b610ce3288e058816dbb096c8b344e6f0c056706273dcbbf55b80
7
- data.tar.gz: 93dff92101055f58ef493c1e1574c716683315a452add2b43522ef6a4e7b25c6d38caf9e2791a2ed8162c9b541b465d275ec09e699c6f3ad794b537ba8fb3e74
6
+ metadata.gz: 91bec3c1dfd3c450fb0565794026c0dcba137db1c42e5fb79a63544e4071c7ece69e36a2c42b9a5e45cf8790a1fca769c25ce6dc9f9050819a4c7dae7216bb5f
7
+ data.tar.gz: 20e8f730c627d53ad7558240d808c2ac42e0540b57e0e78814e560668e80af18c0c83014eefb3d335356dd8bb58ff27425f412f0a8054921171e206cff6a88cf
data/.travis.yml CHANGED
@@ -4,46 +4,45 @@ cache: bundler
4
4
 
5
5
  rvm:
6
6
  - 1.9.3
7
- - 2.2.5
8
- - 2.3.1
7
+ - 2.2.6
8
+ - 2.3.3
9
9
  - jruby-1.7 # JRuby in 1.9 mode
10
10
  - jruby-9.0.5.0
11
- - rbx-2.5.8
12
11
 
13
12
  services:
14
13
  - mongodb
15
14
  - redis-server
16
15
 
17
16
  gemfile:
18
- - gemfiles/rails_3.2_stable.gemfile
17
+ - gemfiles/rails_3.2.gemfile
19
18
  - gemfiles/rails_4.0.gemfile
20
- - gemfiles/rails_4.0_mongo_mapper.gemfile
21
19
  - gemfiles/rails_4.2.gemfile
22
20
  - gemfiles/rails_4.2_mongoid_5.gemfile
23
- - gemfiles/rails_4.2_mongo_mapper.gemfile
24
21
  - gemfiles/rails_5.0.gemfile
25
22
 
26
23
  before_script:
27
24
  - mkdir /tmp/dynamodb
28
- - wget -O - http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest | tar xz --directory /tmp/dynamodb
25
+ - wget -O - http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz | tar xz --directory /tmp/dynamodb
29
26
  - java -Djava.library.path=/tmp/dynamodb/DynamoDBLocal_lib -jar /tmp/dynamodb/DynamoDBLocal.jar -inMemory -delayTransientStatuses -port 30180 &
27
+ - mongod --version
30
28
 
31
29
  matrix:
32
- allow_failures:
33
- - rvm: jruby-9.0.5.0
34
- gemfile: gemfiles/rails_5.0.gemfile
35
- - rvm: rbx-2.5.8
36
- gemfile: gemfiles/rails_5.0.gemfile
37
30
  exclude:
31
+ - rvm: 1.9.3
32
+ gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
38
33
  - rvm: 1.9.3
39
34
  gemfile: gemfiles/rails_5.0.gemfile
40
- - rvm: 2.2.5
41
- gemfile: gemfiles/rails_3.2_stable.gemfile
42
- - rvm: 2.3.1
43
- gemfile: gemfiles/rails_3.2_stable.gemfile
35
+ - rvm: 2.2.6
36
+ gemfile: gemfiles/rails_3.2.gemfile
37
+ - rvm: 2.3.3
38
+ gemfile: gemfiles/rails_3.2.gemfile
44
39
  - rvm: jruby-1.7
40
+ gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
41
+ - rvm: jruby-1.7
42
+ gemfile: gemfiles/rails_5.0.gemfile
43
+ - rvm: jruby-9.0.5.0
45
44
  gemfile: gemfiles/rails_5.0.gemfile
46
45
 
47
46
  notifications:
48
47
  slack:
49
- secure: MsPY8sUW5TVblcWc5NGkkWJlHxCMnhNa3IFPSVWthlk0fz+CLfOrLjQ+brQup/AJ7BRtyBKQ8udpqLj/R7CJKAiVVDAlUBcHqXk/WDusssGzJkDMrLVDefq++YCg5TdbcIaHt8WBVg6pD8H4kQJMJxmtcziQtiW1Qt0pwfuNJ+k=
48
+ secure: gpltVWntdKz0nSE6A5UvuX4qbN35uW51nsW+Ojgqm8Qsv8K240/NlZRYutFHr7GnJTe0rEEP2Oy3ZBnBtZKFn13RlTEAU/FCAxebr4H24rr29Ypwwp5xjiSE4MuoBEnroo4lw6ka3LsJnrY2PKRMiLJGsS0WsEPY4x8NUG/vyY8=
data/Appraisals ADDED
@@ -0,0 +1,44 @@
1
+ appraise 'rails_3.2' do
2
+ gem 'rails', '~>3.2.22'
3
+ gem 'mongoid', '~>3.1'
4
+ gem 'sequel'
5
+ gem 'bson_ext', :platforms => :ruby
6
+ gem 'test-unit', '~> 3.0'
7
+ end
8
+
9
+ appraise 'rails_4.0' do
10
+ gem 'mime-types', '~> 2', :platforms => [:ruby_19, :jruby]
11
+ gem 'rails', '4.0.13'
12
+ gem 'mongoid', '~>4.0'
13
+ gem 'sequel'
14
+ gem 'dynamoid', '~> 1', :platforms => :ruby
15
+ gem 'aws-sdk', '~>2', :platforms => :ruby
16
+ gem 'redis-objects'
17
+ end
18
+
19
+ appraise 'rails_4.2' do
20
+ gem 'nokogiri', '1.6.8.1', :platforms => [:ruby_19]
21
+ gem 'mime-types', '~> 2', :platforms => [:ruby_19, :jruby]
22
+ gem 'rails', '4.2.5'
23
+ gem 'mongoid', '~>4.0'
24
+ gem 'sequel'
25
+ gem 'dynamoid', '~> 1', :platforms => :ruby
26
+ gem 'aws-sdk', '~>2', :platforms => :ruby
27
+ end
28
+
29
+ appraise 'rails_4.2_mongoid_5' do
30
+ gem 'mime-types', '~> 2', :platforms => [:ruby_19, :jruby]
31
+ gem 'rails', '4.2.5'
32
+ gem 'mongoid', '~>5.0'
33
+ end
34
+
35
+ appraise 'rails_5.0' do
36
+ gem 'rails', '5.0.0'
37
+ gem 'mongoid', '~>6.0'
38
+ gem 'sequel'
39
+
40
+ # dynamoid is not yet Rails 5 compatible
41
+ # gem 'dynamoid', '~> 1', :platforms => :ruby
42
+
43
+ gem 'aws-sdk', '~>2', :platforms => :ruby
44
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## unreleased
4
+
5
+ ## 4.12.0
6
+
7
+ * Fix thread safe issue with concurrent-ruby gem [see [pull-request #422](https://github.com/aasm/aasm/pull/442), thanks to [@reidmorrison](https://github.com/reidmorrison)
8
+ * Drop Support for Mongo Mapper [see [pull-request #439](https://github.com/aasm/aasm/pull/439)], thanks to [@reidmorrison](https://github.com/reidmorrison)
9
+ * add :binding_event option to event [see [pull-request #438](https://github.com/aasm/aasm/pull/438)], thanks to [@leanhdaovn](https://github.com/leanhdaovn)
10
+ * fix: `skip_validation_on_save: true` for default_scope records, [see [pull-request #433](https://github.com/aasm/aasm/pull/433)], thanks to [@larissa](https://github.com/larissa)
11
+ * Deep clone state machine during inheritance so that state machines in child classes can be modified (see [pull-request #429](https://github.com/aasm/aasm/pull/429)), thanks to [@reidmorrison](https://github.com/reidmorrison) and [@Tybot204](https://github.com/Tybot204)
12
+ * add before_success callback for event (see [pull-request #422](https://github.com/aasm/aasm/pull/422)), thanks to [@timsly ](https://github.com/timsly)
13
+ * fix: multiple transitions in a single event with the same to and from states (see [issue #372](https://github.com/aasm/aasm/issues/372) and [issue #362](https://github.com/aasm/aasm/issues/362) for details, fixed with [pull-request #408](https://github.com/aasm/aasm/pull/408), thanks to [@dathanb](https://github.com/dathanb))
14
+ * fix: passing nil as a argument to callbacks (see [issue #404](https://github.com/aasm/aasm/issues/404) for details, fixed with [pull-request #406](https://github.com/aasm/aasm/pull/406), thanks to [@yogeshjain999](https://github.com/yogeshjain999))
15
+
16
+
17
+ ## 4.11.1
18
+
19
+ * fix: generator file name when using custom column name instead of
20
+ aasm_state (see [issue #398](https://github.com/aasm/aasm/pull/398) for details,
21
+ thanks to [@bastianwegge](https://github.com/bastianwegge))
22
+ * fix: Scopes when states are defined as a series of symbols (see [issue #397](https://github.com/aasm/aasm/pull/397) for details, thanks to [@evheny0](https://github.com/evheny0))
23
+ * fix: Multiple transition behavior when one of the transitions does not
24
+ have a "from" parameter (see [issue #392](https://github.com/aasm/aasm/issues/392) for details)
25
+ * fix: permissible states not respecting guard parameters (see [issue #388](https://github.com/aasm/aasm/issues/388)) with [pull-request #389](https://github.com/aasm/aasm/pull/389)
26
+
3
27
  ## 4.11.0
4
28
 
5
29
  * support `logger` configuration (see [issue #370](https://github.com/aasm/aasm/pull/370) for details, thanks to [@HoyaBoya](https://github.com/HoyaBoya))
@@ -329,4 +353,3 @@
329
353
 
330
354
  * supporting i18n
331
355
  * supporting regular expressions for hash values and strings
332
-
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,24 @@
1
+ ## Contributing ##
2
+
3
+ While not required to contribute, we recommend [RVM](https://rvm.io/) to manage your rubies.
4
+
5
+ 1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
6
+ 2. [Fork it](https://help.github.com/articles/about-forks/)
7
+ 3. Clone the project `git clone git@github.com:[YOUR GITHUB USERNAME]/aasm.git`
8
+ 4. `cd aasm`
9
+ 5. Create your feature branch `git checkout -b my-new-feature`
10
+ 6. Write tests for your changes (feature/bug)
11
+ 7. Write your (feature/bugfix)
12
+ 8. Install the dependencies `appraisal install`
13
+ 9. Run the tests `appraisal rspec`
14
+ 10. Commit your changes `git commit -am 'Added some feature'`
15
+ 11. Push to the branch `git push origin my-new-feature`
16
+ 12. Create new [Pull Request](https://help.github.com/articles/creating-a-pull-request/)
17
+
18
+ There are some option dependencies as well.
19
+
20
+ - [MongoDB server](https://www.mongodb.com/download-center)
21
+ - [Redis](https://redis.io/topics/quickstart)
22
+ - [DynamoDB (local)](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html)
23
+
24
+ If we've missed something please open an [issue](https://github.com/aasm/aasm/issues/new)
data/Gemfile CHANGED
@@ -1,24 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem "jruby-openssl", :platforms => :jruby
6
- gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
7
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
8
- gem "rails", "~>4.2"
9
- gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
10
- gem 'sequel'
11
-
12
- # testing dynamoid
13
- # gem 'dynamoid', '~> 1'
14
- # gem 'aws-sdk', '~>2'
15
-
16
- # Since mongoid V4 requires incompatible bson V2, cannot have mongoid (V4 or greater)
17
- # and mongo_mapper ( or mongo ) in the same application
18
- # gem 'mongo_mapper', '~> 0.13'
19
- # gem 'bson_ext', :platforms => :ruby
20
-
21
- # uncomment if you want to run specs for Redis persistence
22
- # gem "redis-objects"
23
-
24
3
  gemspec
4
+
5
+ gem 'sqlite3', :platforms => :ruby
6
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
7
+ gem 'rails', '5.0.0'
data/README.md CHANGED
@@ -10,7 +10,7 @@ This package contains AASM, a library for adding finite state machines to Ruby c
10
10
  AASM started as the *acts_as_state_machine* plugin but has evolved into a more generic library
11
11
  that no longer targets only ActiveRecord models. It currently provides adapters for
12
12
  [ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html),
13
- [Mongoid](http://mongoid.org/), and [Mongomapper](http://mongomapper.com/) but it can be used for any Ruby class, no matter what
13
+ and [Mongoid](http://mongoid.org/) but it can be used for any Ruby class, no matter what
14
14
  parent class it has (if any).
15
15
 
16
16
  ## Upgrade from version 3 to 4
@@ -132,7 +132,7 @@ class Job
132
132
  ...
133
133
  end
134
134
 
135
- def notify_somebody(user)
135
+ def notify_somebody
136
136
  ...
137
137
  end
138
138
 
@@ -180,6 +180,7 @@ begin
180
180
  new_state before_enter
181
181
  new_state enter
182
182
  ...update state...
183
+ event before_success # if persist successful
183
184
  transition success # if persist successful
184
185
  event success # if persist successful
185
186
  old_state after_exit
@@ -415,9 +416,71 @@ SimpleMultipleExample.aasm(:work).states
415
416
  # => [:standing, :walking, :running]
416
417
  ```
417
418
 
419
+ ### Binding event
420
+
421
+ Allow an event to be bound to another
422
+ ```ruby
423
+ class Example
424
+ include AASM
425
+
426
+ aasm(:work) do
427
+ state :sleeping, :initial => true
428
+ state :processing
429
+
430
+ event :start do
431
+ transitions :from => :sleeping, :to => :processing
432
+ end
433
+ event :stop do
434
+ transitions :from => :processing, :to => :sleeping
435
+ end
436
+ end
437
+
438
+ aasm(:question) do
439
+ state :answered, :initial => true
440
+ state :asked
441
+
442
+ event :ask, :binding_event => :start do
443
+ transitions :from => :answered, :to => :asked
444
+ end
445
+ event :answer, :binding_event => :stop do
446
+ transitions :from => :asked, :to => :answered
447
+ end
448
+ end
449
+ end
450
+
451
+ example = Example.new
452
+ example.aasm(:work).current_state #=> :sleeping
453
+ example.aasm(:question).current_state #=> :answered
454
+ example.ask
455
+ example.aasm(:work).current_state #=> :processing
456
+ example.aasm(:question).current_state #=> :asked
457
+ ```
458
+
418
459
  *Final note*: Support for multiple state machines per class is a pretty new feature
419
460
  (since version `4.3`), so please bear with us in case it doesn't work as expected.
420
461
 
462
+ ### Auto-generated Status Constants
463
+
464
+ AASM automatically [generates constants](https://github.com/aasm/aasm/pull/60)
465
+ for each status so you don't have to explicitly define them.
466
+
467
+ ```ruby
468
+ class Foo
469
+ include AASM
470
+
471
+ aasm do
472
+ state :initialized
473
+ state :calculated
474
+ state :finalized
475
+ end
476
+ end
477
+
478
+ > Foo::STATE_INITIALIZED
479
+ #=> :initialized
480
+ > Foo::STATE_CALCULATED
481
+ #=> :calculated
482
+ ```
483
+
421
484
  ### Extending AASM
422
485
 
423
486
  AASM allows you to easily extend `AASM::Base` for your own application purposes.
@@ -510,6 +573,8 @@ class Job < ActiveRecord::Base
510
573
  end
511
574
  ```
512
575
 
576
+ ### Bang events
577
+
513
578
  You can tell AASM to auto-save the object or leave it unsaved
514
579
 
515
580
  ```ruby
@@ -518,8 +583,10 @@ job.run # not saved
518
583
  job.run! # saved
519
584
  ```
520
585
 
521
- Saving includes running all validations on the `Job` class, and returns `true` if
522
- successful or `false` if errors occur. Exceptions are not raised.
586
+ Saving includes running all validations on the `Job` class. If
587
+ `whiny_persistence` flag is set to `true`, exception is raised in case of
588
+ failure. If `whiny_persistence` flag is set to false, methods with a bang return
589
+ `true` if the state transition is successful or `false` if an error occurs.
523
590
 
524
591
  If you want make sure the state gets saved without running validations (and
525
592
  thereby maybe persisting an invalid object state), simply tell AASM to skip the
@@ -610,7 +677,7 @@ to ```false```.
610
677
 
611
678
  ### Sequel
612
679
 
613
- AASM also supports [Sequel](http://sequel.jeremyevans.net/) besides _ActiveRecord_, _Mongoid_, and _MongoMapper_.
680
+ AASM also supports [Sequel](http://sequel.jeremyevans.net/) besides _ActiveRecord_, and _Mongoid_.
614
681
 
615
682
  ```ruby
616
683
  class Job < Sequel::Model
@@ -646,23 +713,6 @@ class Job
646
713
  end
647
714
  ```
648
715
 
649
- ### MongoMapper
650
-
651
- AASM also supports persistence to Mongodb if you're using MongoMapper. Make sure
652
- to include MongoMapper::Document before you include AASM.
653
-
654
- ```ruby
655
- class Job
656
- include MongoMapper::Document
657
- include AASM
658
-
659
- key :aasm_state, Symbol
660
- aasm do
661
- ...
662
- end
663
- end
664
- ```
665
-
666
716
  ### Redis
667
717
 
668
718
  AASM also supports persistence in Redis.
@@ -899,13 +949,13 @@ end
899
949
 
900
950
  ```ruby
901
951
  # show all states
902
- Job.aasm.states.map(&:name)
952
+ Job.aasm.states.map(&:name)
903
953
  #=> [:sleeping, :running, :cleaning]
904
954
 
905
955
  job = Job.new
906
956
 
907
957
  # show all permitted states (from initial state)
908
- job.aasm.states(:permitted => true).map(&:name)
958
+ job.aasm.states(:permitted => true).map(&:name)
909
959
  #=> [:running]
910
960
 
911
961
  job.run
@@ -913,7 +963,7 @@ job.aasm.states(:permitted => true).map(&:name)
913
963
  #=> [:sleeping]
914
964
 
915
965
  # show all non permitted states
916
- job.aasm.states(:permitted => false).map(&:name)
966
+ job.aasm.states(:permitted => false).map(&:name)
917
967
  #=> [:cleaning]
918
968
 
919
969
  # show all possible (triggerable) events from the current state
@@ -935,6 +985,9 @@ job.aasm.events(:reject => :sleep).map(&:name)
935
985
  # list states for select
936
986
  Job.aasm.states_for_select
937
987
  => [["Sleeping", "sleeping"], ["Running", "running"], ["Cleaning", "cleaning"]]
988
+
989
+ # show permitted states with guard parameter
990
+ job.aasm.states({:permitted => true}, guard_parameter).map(&:name)
938
991
  ```
939
992
 
940
993
 
@@ -1029,7 +1082,7 @@ gem 'aasm'
1029
1082
 
1030
1083
  ### Generators
1031
1084
 
1032
- After installing Aasm you can run generator:
1085
+ After installing AASM you can run generator:
1033
1086
 
1034
1087
  ```sh
1035
1088
  % rails generate aasm NAME [COLUMN_NAME]
@@ -1055,16 +1108,10 @@ Feel free to
1055
1108
  * [Scott Barron](https://github.com/rubyist) (2006–2009, original author)
1056
1109
  * [Travis Tilley](https://github.com/ttilley) (2009–2011)
1057
1110
  * [Thorsten Böttger](http://github.com/alto) (since 2011)
1111
+ * [Anil Maurya](http://github.com/anilmaurya) (since 2016)
1058
1112
 
1059
1113
 
1060
- ## Contributing ##
1061
-
1062
- 1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
1063
- 2. Fork it
1064
- 3. Create your feature branch (git checkout -b my-new-feature)
1065
- 4. Commit your changes (git commit -am 'Added some feature')
1066
- 5. Push to the branch (git push origin my-new-feature)
1067
- 6. Create new Pull Request
1114
+ ## [Contributing](CONTRIBUTING.md)
1068
1115
 
1069
1116
  ## Warranty ##
1070
1117
 
data/Rakefile CHANGED
@@ -23,4 +23,9 @@ Rake::RDocTask.new do |rdoc|
23
23
  rdoc.rdoc_files.include('lib/**/*.rb')
24
24
  end
25
25
 
26
- task :default => :spec
26
+ if ENV["APPRAISAL_INITIALIZED"] || ENV["TRAVIS"]
27
+ task :default => :spec
28
+ else
29
+ require 'appraisal'
30
+ task :default => :appraisal
31
+ end
data/TESTING.md ADDED
@@ -0,0 +1,25 @@
1
+ ## Install dependency matrix
2
+
3
+ appraisal install
4
+
5
+ This will re-generate Gemfiles in `gemfile` folder
6
+
7
+ Use rvm gemsets or similar to avoid global gem pollution
8
+
9
+ ## Run specs
10
+
11
+ For all supported Rails/ORM combinations:
12
+
13
+ appraisal rspec
14
+
15
+ Or for specific one:
16
+
17
+ appraisal rails_4.2 rspec
18
+
19
+ Or for one particular test file
20
+
21
+ appraisal rails_4.2_mongoid_5 rspec spec/unit/persistence/mongoid_persistence_multiple_spec.rb
22
+
23
+ Or down to one test case
24
+
25
+ appraisal rails_4.2_mongoid_5 rspec spec/unit/persistence/mongoid_persistence_multiple_spec.rb:92
data/aasm.gemspec CHANGED
@@ -5,8 +5,8 @@ require "aasm/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "aasm"
7
7
  s.version = AASM::VERSION
8
- s.authors = ["Scott Barron", "Travis Tilley", "Thorsten Boettger"]
9
- s.email = %q{scott@elitists.net, ttilley@gmail.com, aasm@mt7.de}
8
+ s.authors = ["Thorsten Boettger", "Anil Maurya"]
9
+ s.email = %q{aasm@mt7.de, anilmaurya8dec@gmail.com}
10
10
  s.homepage = %q{https://github.com/aasm/aasm}
11
11
  s.summary = %q{State machine mixin for Ruby objects}
12
12
  s.description = %q{AASM is a continuation of the acts-as-state-machine rails plugin, built for plain Ruby objects.}
@@ -16,10 +16,13 @@ Gem::Specification.new do |s|
16
16
  s.platform = Gem::Platform::RUBY
17
17
  s.required_ruby_version = '>= 1.9.3'
18
18
 
19
+ s.add_dependency 'concurrent-ruby', '~> 1.0'
20
+
19
21
  s.add_development_dependency 'rake'
20
22
  s.add_development_dependency 'sdoc'
21
23
  s.add_development_dependency 'rspec', ">= 3"
22
24
  s.add_development_dependency 'generator_spec'
25
+ s.add_development_dependency 'appraisal'
23
26
 
24
27
  # debugging
25
28
  # s.add_development_dependency 'debugger'
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", :platforms => :ruby
6
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
7
+ gem "rails", "~>3.2.22"
8
+ gem "mongoid", "~>3.1"
9
+ gem "sequel"
10
+ gem "bson_ext", :platforms => :ruby
11
+ gem "test-unit", "~> 3.0"
12
+
13
+ gemspec :path => "../"
@@ -1,16 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem 'rubinius-developer_tools', :platforms => :rbx
6
- gem "jruby-openssl", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
7
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
9
7
  gem "rails", "4.0.13"
10
- gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
11
- gem 'sequel'
12
- gem 'dynamoid', '~> 1', :platforms => :ruby
13
- gem 'aws-sdk', '~>2', :platforms => :ruby
8
+ gem "mime-types", "~> 2", :platforms => [:ruby_19, :jruby]
9
+ gem "mongoid", "~>4.0"
10
+ gem "sequel"
11
+ gem "dynamoid", "~> 1", :platforms => :ruby
12
+ gem "aws-sdk", "~>2", :platforms => :ruby
14
13
  gem "redis-objects"
15
14
 
16
15
  gemspec :path => "../"
@@ -1,15 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem 'rubinius-developer_tools', :platforms => :rbx
6
- gem "jruby-openssl", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
7
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
9
7
  gem "rails", "4.2.5"
10
- gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
11
- gem 'sequel'
12
- gem 'dynamoid', '~> 1', :platforms => :ruby
13
- gem 'aws-sdk', '~>2', :platforms => :ruby
8
+ gem "nokogiri", "1.6.8.1", :platforms => [:ruby_19]
9
+ gem "mime-types", "~> 2", :platforms => [:ruby_19, :jruby]
10
+ gem "mongoid", "~>4.0"
11
+ gem "sequel"
12
+ gem "dynamoid", "~> 1", :platforms => :ruby
13
+ gem "aws-sdk", "~>2", :platforms => :ruby
14
14
 
15
15
  gemspec :path => "../"
@@ -1,15 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem 'rubinius-developer_tools', :platforms => :rbx
6
- gem "jruby-openssl", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
7
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "mime-types", "~> 2" if Gem::Version.create(RUBY_VERSION.dup) <= Gem::Version.create('1.9.3')
9
7
  gem "rails", "4.2.5"
10
- gem 'mongoid', '~>5.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
11
- gem 'sequel'
12
- gem 'dynamoid', '~> 1', :platforms => :ruby
13
- gem 'aws-sdk', '~>2', :platforms => :ruby
8
+ gem "mime-types", "~> 2", :platforms => [:ruby_19, :jruby]
9
+ gem "mongoid", "~>5.0"
14
10
 
15
11
  gemspec :path => "../"
@@ -1,21 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- gem "sqlite3", :platforms => :ruby
4
- gem 'rubysl', :platforms => :rbx
5
- gem 'rubinius-developer_tools', :platforms => :rbx
6
- gem "jruby-openssl", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
7
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
-
9
- gem "rails", "5.0.0.beta4"
10
-
11
- # mongoid is not yet Rails 5 compatible
12
- # gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
13
-
14
- gem 'sequel'
15
-
16
- # dynamoid is not yet Rails 5 compatible
17
- # gem 'dynamoid', '~> 1', :platforms => :ruby
18
-
19
- gem 'aws-sdk', '~>2', :platforms => :ruby
7
+ gem "rails", "5.0.0"
8
+ gem "mongoid", "~>6.0"
9
+ gem "sequel"
10
+ gem "aws-sdk", "~>2", :platforms => :ruby
20
11
 
21
12
  gemspec :path => "../"
data/lib/aasm/aasm.rb CHANGED
@@ -42,7 +42,7 @@ module AASM
42
42
 
43
43
  raise ArgumentError, "The class #{aasm_klass} must inherit from AASM::Base!" unless aasm_klass.ancestors.include?(AASM::Base)
44
44
 
45
- @aasm ||= {}
45
+ @aasm ||= Concurrent::Map.new
46
46
  if @aasm[state_machine_name]
47
47
  # make sure to use provided options
48
48
  options.each do |key, value|
@@ -67,12 +67,12 @@ module AASM
67
67
  unless AASM::StateMachineStore.fetch(self.class, true).machine(name)
68
68
  raise AASM::UnknownStateMachineError.new("There is no state machine with the name '#{name}' defined in #{self.class.name}!")
69
69
  end
70
- @aasm ||= {}
70
+ @aasm ||= Concurrent::Map.new
71
71
  @aasm[name.to_sym] ||= AASM::InstanceBase.new(self, name.to_sym)
72
72
  end
73
73
 
74
74
  def initialize_dup(other)
75
- @aasm = {}
75
+ @aasm = Concurrent::Map.new
76
76
  super
77
77
  end
78
78
 
@@ -150,6 +150,7 @@ private
150
150
  persist_successful = aasm(state_machine_name).set_current_state_with_persistence(new_state_name)
151
151
  if persist_successful
152
152
  yield if block_given?
153
+ event.fire_callbacks(:before_success, self)
153
154
  event.fire_transition_callbacks(self, *process_args(event, old_state.name, *args))
154
155
  event.fire_callbacks(:success, self)
155
156
  end
@@ -158,6 +159,11 @@ private
158
159
  yield if block_given?
159
160
  end
160
161
 
162
+ binding_event = event.options[:binding_event]
163
+ if binding_event
164
+ __send__("#{binding_event}#{'!' if persist}")
165
+ end
166
+
161
167
  if persist_successful
162
168
  old_state.fire_callbacks(:after_exit, self,
163
169
  *process_args(event, aasm(state_machine_name).current_state, *args))
data/lib/aasm/base.rb CHANGED
@@ -208,7 +208,9 @@ module AASM
208
208
  klass.defined_enums.values.any?{ |methods|
209
209
  methods.keys{| enum | enum + '?' == method_name }
210
210
  })
211
- @state_machine.config.logger.warn "#{klass.name}: overriding method '#{method_name}'!"
211
+ unless AASM::Configuration.hide_warnings
212
+ @state_machine.config.logger.warn "#{klass.name}: overriding method '#{method_name}'!"
213
+ end
212
214
  end
213
215
 
214
216
  klass.send(:define_method, method_name, method_definition)