aasm 4.0.8 → 4.2.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/.travis.yml +5 -2
- data/CHANGELOG.md +18 -2
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +6 -3
- data/LICENSE +1 -1
- data/README.md +31 -5
- data/aasm.gemspec +1 -5
- data/gemfiles/rails_3.2.gemfile +3 -2
- data/gemfiles/rails_4.0.gemfile +2 -6
- data/gemfiles/rails_4.0_bson1.gemfile +14 -0
- data/gemfiles/rails_4.1.gemfile +2 -6
- data/gemfiles/rails_4.1_bson1.gemfile +14 -0
- data/gemfiles/rails_4.2.gemfile +1 -5
- data/gemfiles/rails_4.2_bson1.gemfile +14 -0
- data/lib/aasm/aasm.rb +13 -7
- data/lib/aasm/base.rb +12 -4
- data/lib/aasm/core/event.rb +1 -1
- data/lib/aasm/core/state.rb +8 -6
- data/lib/aasm/errors.rb +12 -1
- data/lib/aasm/persistence/active_record_persistence.rb +4 -4
- data/lib/aasm/persistence/base.rb +3 -0
- data/lib/aasm/persistence/mongo_mapper_persistence.rb +174 -0
- data/lib/aasm/persistence/mongoid_persistence.rb +1 -5
- data/lib/aasm/persistence/sequel_persistence.rb +1 -0
- data/lib/aasm/persistence.rb +2 -0
- data/lib/aasm/version.rb +1 -1
- data/spec/models/active_record/derivate_new_dsl.rb +3 -0
- data/spec/models/active_record/false_state.rb +17 -0
- data/spec/models/active_record/gate.rb +19 -0
- data/spec/models/active_record/localizer_test_model.rb +34 -0
- data/spec/models/active_record/no_direct_assignment.rb +10 -0
- data/spec/models/active_record/no_scope.rb +10 -0
- data/spec/models/active_record/persisted_state.rb +12 -0
- data/spec/models/active_record/provided_and_persisted_state.rb +24 -0
- data/spec/models/active_record/reader.rb +7 -0
- data/spec/models/active_record/simple_new_dsl.rb +8 -0
- data/spec/models/active_record/thief.rb +14 -0
- data/spec/models/active_record/transient.rb +6 -0
- data/spec/models/active_record/with_enum.rb +19 -0
- data/spec/models/active_record/with_false_enum.rb +15 -0
- data/spec/models/active_record/with_true_enum.rb +19 -0
- data/spec/models/active_record/writer.rb +6 -0
- data/spec/models/callbacks/with_args.rb +9 -9
- data/spec/models/{auth_machine.rb → complex_example.rb} +1 -1
- data/spec/models/default_state.rb +12 -0
- data/spec/models/initial_state_proc.rb +15 -0
- data/spec/models/mongo_mapper/no_scope_mongo_mapper.rb +10 -0
- data/spec/models/mongo_mapper/simple_mongo_mapper.rb +11 -0
- data/spec/models/mongo_mapper/simple_new_dsl_mongo_mapper.rb +12 -0
- data/spec/models/mongoid/simple_new_dsl_mongoid.rb +1 -1
- data/spec/models/{bar.rb → no_initial_state.rb} +1 -4
- data/spec/models/provided_state.rb +24 -0
- data/spec/models/simple_example.rb +15 -0
- data/spec/models/state_machine_with_failed_event.rb +12 -0
- data/spec/models/sub_class.rb +3 -0
- data/spec/models/sub_class_with_more_states.rb +7 -0
- data/spec/models/super_class.rb +18 -0
- data/spec/models/{argument.rb → valid_state_name.rb} +1 -1
- data/spec/models/validator.rb +8 -0
- data/spec/spec_helper.rb +3 -4
- data/spec/unit/api_spec.rb +6 -1
- data/spec/unit/callbacks_spec.rb +1 -1
- data/spec/unit/complex_example_spec.rb +2 -2
- data/spec/unit/event_naming_spec.rb +2 -15
- data/spec/unit/initial_state_spec.rb +3 -18
- data/spec/unit/inspection_spec.rb +7 -7
- data/spec/unit/localizer_spec.rb +0 -38
- data/spec/unit/persistence/active_record_persistence_spec.rb +26 -3
- data/spec/unit/persistence/mongo_mapper_persistance_spec.rb +135 -0
- data/spec/unit/persistence/mongoid_persistance_spec.rb +4 -10
- data/spec/unit/persistence/sequel_persistence_spec.rb +15 -1
- data/spec/unit/simple_example_spec.rb +26 -42
- data/spec/unit/subclassing_spec.rb +10 -10
- data/spec/unit/transition_spec.rb +6 -1
- metadata +72 -19
- data/spec/models/active_record/api.rb +0 -75
- data/spec/models/father.rb +0 -21
- data/spec/models/persistence.rb +0 -164
- data/spec/models/son.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd80c470206244734a77fe540848e299e87dab9f
|
|
4
|
+
data.tar.gz: 28b464e9012345a46ddc5595d29541d52a358bf4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 46d54cc3e2e66387916f7f1edfe03f3de9cb09578a8b485ea084bd68ba854f9003d1fd00de18a6d7c40984a0b0d2fe1b2d7bc4b3610e7d421c724e2f5af7a9f1
|
|
7
|
+
data.tar.gz: cb2506c237a22fc3dc04869791d15f85614ac33096ccff60fa5a6dd40830d2325375ed13cdc3abf2adc02c958a336362027393c6ee0351bc463cf47cb0b9020f
|
data/.travis.yml
CHANGED
|
@@ -10,7 +10,7 @@ rvm:
|
|
|
10
10
|
- 2.1
|
|
11
11
|
- 2.2
|
|
12
12
|
# - jruby-18mode # JRuby in 1.8 mode
|
|
13
|
-
- jruby-
|
|
13
|
+
- jruby-1.7 # JRuby in 1.9 mode
|
|
14
14
|
- rbx-2.2.1
|
|
15
15
|
|
|
16
16
|
services: mongodb
|
|
@@ -18,13 +18,16 @@ services: mongodb
|
|
|
18
18
|
gemfile:
|
|
19
19
|
- gemfiles/rails_3.2.gemfile
|
|
20
20
|
- gemfiles/rails_4.0.gemfile
|
|
21
|
+
- gemfiles/rails_4.0_bson1.gemfile
|
|
21
22
|
- gemfiles/rails_4.1.gemfile
|
|
23
|
+
- gemfiles/rails_4.1_bson1.gemfile
|
|
22
24
|
- gemfiles/rails_4.2.gemfile
|
|
25
|
+
- gemfiles/rails_4.2_bson1.gemfile
|
|
23
26
|
|
|
24
27
|
matrix:
|
|
25
28
|
allow_failures:
|
|
26
29
|
- rvm: rbx-2.2.1
|
|
27
|
-
- rvm: jruby-
|
|
30
|
+
- rvm: jruby-1.7
|
|
28
31
|
exclude:
|
|
29
32
|
- rvm: 1.9.3
|
|
30
33
|
gemfile: gemfiles/rails_4.1.gemfile
|
data/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
## 4.
|
|
3
|
+
## 4.3.0 (not yet released)
|
|
4
4
|
|
|
5
|
+
## 4.2.0
|
|
6
|
+
|
|
7
|
+
* support turning off and on the configuration option for `no_direct_assignment` (see [issue #223](https://github.com/aasm/aasm/issues/223) for details)
|
|
8
|
+
* event arguments are now passed to `:after_commit` callbacks as well (see [issue #238](https://github.com/aasm/aasm/pull/238), thanks to [@kuinak](https://github.com/kuinak))
|
|
9
|
+
|
|
10
|
+
## 4.1.1
|
|
11
|
+
|
|
12
|
+
* support block notation for `:after_commit` event callbacks (see [issue #224](https://github.com/aasm/aasm/issues/224) for details)
|
|
13
|
+
* event arguments are now passed to state callbacks as well (not only to event callbacks) (see [issue #219](https://github.com/aasm/aasm/issues/219), thanks to [@tobithiel](https://github.com/tobithiel))
|
|
14
|
+
* `AASM::InvalidTransition` now references the current object (with the state machine) and the _AASM_ event name (see [issue #217](https://github.com/aasm/aasm/issues/217), thanks to [@awsmsrc](https://github.com/awsmsrc))
|
|
15
|
+
* bugfix: do not update unloaded state for [Sequel](http://sequel.jeremyevans.net/) (see [issue #218](https://github.com/aasm/aasm/issues/218), thanks to [@godfat](https://github.com/godfat))
|
|
16
|
+
|
|
17
|
+
## 4.1.0
|
|
18
|
+
|
|
19
|
+
* bugfix: initialize the aasm state column after initialization of the _Mongoid_ instance (see [issue #206](https://github.com/aasm/aasm/issues/206), thanks to [@Shwetakale ](https://github.com/Shwetakale ))
|
|
20
|
+
* added support for mongomapper ORM (see [issue #203](https://github.com/aasm/aasm/issues/203), thanks to [@reidmorrison ](https://github.com/reidmorrison ))
|
|
5
21
|
* `aasm_column` has been removed. Use `aasm.attribute_name` instead
|
|
6
22
|
* `aasm_human_event_name` has been removed. Use `aasm.human_event_name` instead
|
|
7
23
|
|
|
8
24
|
## 4.0.8
|
|
9
25
|
|
|
10
|
-
* bugfix:
|
|
26
|
+
* bugfix: may_event_name? should return true or false only (see [issue #200](https://github.com/aasm/aasm/issues/200) for details)
|
|
11
27
|
|
|
12
28
|
## 4.0.7
|
|
13
29
|
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
|
4
|
+
|
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
|
6
|
+
|
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
|
8
|
+
|
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
|
10
|
+
|
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
|
12
|
+
|
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gem "sqlite3", :platforms => :ruby
|
|
4
|
-
gem "coveralls", :platforms => :ruby
|
|
5
4
|
gem 'rubysl', :platforms => :rbx
|
|
6
5
|
gem "jruby-openssl", :platforms => :jruby
|
|
7
6
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
8
|
-
gem "rails", "~>4.
|
|
9
|
-
gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
7
|
+
gem "rails", "~>4.2"
|
|
8
|
+
gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
10
9
|
gem 'sequel'
|
|
10
|
+
# Since mongoid V4 requires incompatible bson V2, cannot have mongoid (V4 or greater)
|
|
11
|
+
# and mongo_mapper ( or mongo ) in the same application
|
|
12
|
+
#gem 'mongo_mapper', '~> 0.13'
|
|
13
|
+
#gem 'bson_ext', :platforms => :ruby
|
|
11
14
|
|
|
12
15
|
gemspec
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://badge.fury.io/rb/aasm)
|
|
4
4
|
[](https://travis-ci.org/aasm/aasm)
|
|
5
|
+
[](https://gemnasium.com/aasm/aasm)
|
|
5
6
|
[](https://codeclimate.com/github/aasm/aasm)
|
|
6
|
-
[](https://coveralls.io/r/aasm/aasm?branch=master)
|
|
7
7
|
|
|
8
8
|
This package contains AASM, a library for adding finite state machines to Ruby classes.
|
|
9
9
|
|
|
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
|
-
[ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html)
|
|
13
|
-
[Mongoid](http://mongoid.org/), but it can be used for any Ruby class, no matter what
|
|
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
|
|
14
14
|
parent class it has (if any).
|
|
15
15
|
|
|
16
16
|
## Upgrade from version 3 to 4
|
|
@@ -435,7 +435,7 @@ to ```false```.
|
|
|
435
435
|
|
|
436
436
|
### Sequel
|
|
437
437
|
|
|
438
|
-
AASM also supports [Sequel](http://sequel.jeremyevans.net/) besides _ActiveRecord_ and
|
|
438
|
+
AASM also supports [Sequel](http://sequel.jeremyevans.net/) besides _ActiveRecord_, _Mongoid_, and _MongoMapper_.
|
|
439
439
|
|
|
440
440
|
```ruby
|
|
441
441
|
class Job < Sequel::Model
|
|
@@ -466,6 +466,23 @@ class Job
|
|
|
466
466
|
end
|
|
467
467
|
```
|
|
468
468
|
|
|
469
|
+
### MongoMapper
|
|
470
|
+
|
|
471
|
+
AASM also supports persistence to Mongodb if you're using MongoMapper. Make sure
|
|
472
|
+
to include MongoMapper::Document before you include AASM.
|
|
473
|
+
|
|
474
|
+
```ruby
|
|
475
|
+
class Job
|
|
476
|
+
include MongoMapper::Document
|
|
477
|
+
include AASM
|
|
478
|
+
|
|
479
|
+
key :aasm_state, Symbol
|
|
480
|
+
aasm do
|
|
481
|
+
...
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
```
|
|
485
|
+
|
|
469
486
|
### Automatic Scopes
|
|
470
487
|
|
|
471
488
|
AASM will automatically create scope methods for each state in the model.
|
|
@@ -662,6 +679,15 @@ Feel free to
|
|
|
662
679
|
* [Thorsten Böttger](http://github.com/alto) (since 2011)
|
|
663
680
|
|
|
664
681
|
|
|
682
|
+
## Contributing ##
|
|
683
|
+
|
|
684
|
+
1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
|
|
685
|
+
2. Fork it
|
|
686
|
+
3. Create your feature branch (git checkout -b my-new-feature)
|
|
687
|
+
4. Commit your changes (git commit -am 'Added some feature')
|
|
688
|
+
5. Push to the branch (git push origin my-new-feature)
|
|
689
|
+
6. Create new Pull Request
|
|
690
|
+
|
|
665
691
|
## Warranty ##
|
|
666
692
|
|
|
667
693
|
This software is provided "as is" and without any express or
|
|
@@ -671,7 +697,7 @@ purpose.
|
|
|
671
697
|
|
|
672
698
|
## License ##
|
|
673
699
|
|
|
674
|
-
Copyright (c) 2006-
|
|
700
|
+
Copyright (c) 2006-2015 Scott Barron
|
|
675
701
|
|
|
676
702
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
677
703
|
a copy of this software and associated documentation files (the
|
data/aasm.gemspec
CHANGED
|
@@ -18,16 +18,12 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
|
|
19
19
|
s.add_development_dependency 'rake'
|
|
20
20
|
s.add_development_dependency 'sdoc'
|
|
21
|
-
s.add_development_dependency 'rspec'
|
|
21
|
+
s.add_development_dependency 'rspec', ">= 3"
|
|
22
22
|
|
|
23
23
|
# debugging
|
|
24
24
|
# s.add_development_dependency 'debugger'
|
|
25
25
|
s.add_development_dependency 'pry'
|
|
26
26
|
|
|
27
|
-
# test coverage
|
|
28
|
-
# s.add_development_dependency 'mime-types', '~> 1.25' # needed by coveralls (>= 2.0 needs Ruby >=1.9.2)
|
|
29
|
-
# s.add_development_dependency 'coveralls'
|
|
30
|
-
|
|
31
27
|
s.files = `git ls-files`.split("\n")
|
|
32
28
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
33
29
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/gemfiles/rails_3.2.gemfile
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gem "sqlite3", :platforms => :ruby
|
|
4
|
-
gem "coveralls"
|
|
5
4
|
gem 'rubysl', :platforms => :rbx
|
|
6
5
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
|
7
6
|
gem "jruby-openssl", :platforms => :jruby
|
|
8
7
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
9
8
|
gem "rails", "3.2.21"
|
|
10
|
-
gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
9
|
+
gem 'mongoid', '~>3.1' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
11
10
|
gem 'sequel'
|
|
11
|
+
gem 'mongo_mapper', '~>0.13'
|
|
12
|
+
gem 'bson_ext', :platforms => :ruby
|
|
12
13
|
|
|
13
14
|
gemspec :path => "../"
|
data/gemfiles/rails_4.0.gemfile
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gem "sqlite3", :platforms => :ruby
|
|
4
|
-
gem "coveralls"
|
|
5
4
|
gem 'rubysl', :platforms => :rbx
|
|
6
5
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
|
7
6
|
gem "jruby-openssl", :platforms => :jruby
|
|
8
7
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
9
|
-
gem "rails", "4.0.
|
|
10
|
-
|
|
11
|
-
# mongoid is not yet compatible with Rails >= 4
|
|
12
|
-
# gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
13
|
-
|
|
8
|
+
gem "rails", "4.0.13"
|
|
9
|
+
gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
14
10
|
gem 'sequel'
|
|
15
11
|
|
|
16
12
|
gemspec :path => "../"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gem "sqlite3", :platforms => :ruby
|
|
4
|
+
gem "coveralls"
|
|
5
|
+
gem 'rubysl', :platforms => :rbx
|
|
6
|
+
gem 'rubinius-developer_tools', :platforms => :rbx
|
|
7
|
+
gem "jruby-openssl", :platforms => :jruby
|
|
8
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
9
|
+
gem "rails", "4.0.13"
|
|
10
|
+
gem 'sequel'
|
|
11
|
+
gem 'mongo_mapper', '~>0.13'
|
|
12
|
+
gem 'bson_ext', :platforms => :ruby
|
|
13
|
+
|
|
14
|
+
gemspec :path => "../"
|
data/gemfiles/rails_4.1.gemfile
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gem "sqlite3", :platforms => :ruby
|
|
4
|
-
gem "coveralls"
|
|
5
4
|
gem 'rubysl', :platforms => :rbx
|
|
6
5
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
|
7
6
|
gem "jruby-openssl", :platforms => :jruby
|
|
8
7
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
9
|
-
gem "rails", "4.1.
|
|
10
|
-
|
|
11
|
-
# mongoid is not yet compatible with Rails >= 4
|
|
12
|
-
# gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
13
|
-
|
|
8
|
+
gem "rails", "4.1.9"
|
|
9
|
+
gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
14
10
|
gem 'sequel'
|
|
15
11
|
|
|
16
12
|
gemspec :path => "../"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gem "sqlite3", :platforms => :ruby
|
|
4
|
+
gem "coveralls"
|
|
5
|
+
gem 'rubysl', :platforms => :rbx
|
|
6
|
+
gem 'rubinius-developer_tools', :platforms => :rbx
|
|
7
|
+
gem "jruby-openssl", :platforms => :jruby
|
|
8
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
9
|
+
gem "rails", "4.1.9"
|
|
10
|
+
gem 'sequel'
|
|
11
|
+
gem 'mongo_mapper', '~> 0.13'
|
|
12
|
+
gem 'bson_ext', :platforms => :ruby
|
|
13
|
+
|
|
14
|
+
gemspec :path => "../"
|
data/gemfiles/rails_4.2.gemfile
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gem "sqlite3", :platforms => :ruby
|
|
4
|
-
gem "coveralls"
|
|
5
4
|
gem 'rubysl', :platforms => :rbx
|
|
6
5
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
|
7
6
|
gem "jruby-openssl", :platforms => :jruby
|
|
8
7
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
9
8
|
gem "rails", "4.2.0"
|
|
10
|
-
|
|
11
|
-
# mongoid is not yet compatible with Rails >= 4
|
|
12
|
-
# gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
13
|
-
|
|
9
|
+
gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
|
14
10
|
gem 'sequel'
|
|
15
11
|
|
|
16
12
|
gemspec :path => "../"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gem "sqlite3", :platforms => :ruby
|
|
4
|
+
gem "coveralls"
|
|
5
|
+
gem 'rubysl', :platforms => :rbx
|
|
6
|
+
gem 'rubinius-developer_tools', :platforms => :rbx
|
|
7
|
+
gem "jruby-openssl", :platforms => :jruby
|
|
8
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
|
9
|
+
gem "rails", "4.2.0"
|
|
10
|
+
gem 'sequel'
|
|
11
|
+
gem 'mongo_mapper'
|
|
12
|
+
gem 'bson_ext', :platforms => :ruby
|
|
13
|
+
|
|
14
|
+
gemspec :path => "../"
|
data/lib/aasm/aasm.rb
CHANGED
|
@@ -69,8 +69,10 @@ private
|
|
|
69
69
|
)
|
|
70
70
|
|
|
71
71
|
if may_fire_to = event.may_fire?(self, *args)
|
|
72
|
-
old_state.fire_callbacks(:before_exit, self
|
|
73
|
-
|
|
72
|
+
old_state.fire_callbacks(:before_exit, self,
|
|
73
|
+
*process_args(event, aasm.current_state, *args))
|
|
74
|
+
old_state.fire_callbacks(:exit, self,
|
|
75
|
+
*process_args(event, aasm.current_state, *args)) # TODO: remove for AASM 4?
|
|
74
76
|
|
|
75
77
|
if new_state_name = event.fire(self, {:may_fire => may_fire_to}, *args)
|
|
76
78
|
aasm_fired(event, old_state, new_state_name, options, *args, &block)
|
|
@@ -90,9 +92,11 @@ private
|
|
|
90
92
|
|
|
91
93
|
new_state = aasm.state_object_for_name(new_state_name)
|
|
92
94
|
|
|
93
|
-
new_state.fire_callbacks(:before_enter, self
|
|
95
|
+
new_state.fire_callbacks(:before_enter, self,
|
|
96
|
+
*process_args(event, aasm.current_state, *args))
|
|
94
97
|
|
|
95
|
-
new_state.fire_callbacks(:enter, self
|
|
98
|
+
new_state.fire_callbacks(:enter, self,
|
|
99
|
+
*process_args(event, aasm.current_state, *args)) # TODO: remove for AASM 4?
|
|
96
100
|
|
|
97
101
|
persist_successful = true
|
|
98
102
|
if persist
|
|
@@ -107,8 +111,10 @@ private
|
|
|
107
111
|
end
|
|
108
112
|
|
|
109
113
|
if persist_successful
|
|
110
|
-
old_state.fire_callbacks(:after_exit, self
|
|
111
|
-
|
|
114
|
+
old_state.fire_callbacks(:after_exit, self,
|
|
115
|
+
*process_args(event, aasm.current_state, *args))
|
|
116
|
+
new_state.fire_callbacks(:after_enter, self,
|
|
117
|
+
*process_args(event, aasm.current_state, *args))
|
|
112
118
|
event.fire_callbacks(
|
|
113
119
|
:after,
|
|
114
120
|
self,
|
|
@@ -129,7 +135,7 @@ private
|
|
|
129
135
|
end
|
|
130
136
|
|
|
131
137
|
if AASM::StateMachine[self.class].config.whiny_transitions
|
|
132
|
-
raise AASM::InvalidTransition,
|
|
138
|
+
raise AASM::InvalidTransition.new(self, event_name)
|
|
133
139
|
else
|
|
134
140
|
false
|
|
135
141
|
end
|
data/lib/aasm/base.rb
CHANGED
|
@@ -27,11 +27,19 @@ module AASM
|
|
|
27
27
|
|
|
28
28
|
configure :enum, nil
|
|
29
29
|
|
|
30
|
-
if
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
# make sure to raise an error if no_direct_assignment is enabled
|
|
31
|
+
# and attribute is directly assigned though
|
|
32
|
+
@klass.class_eval %Q(
|
|
33
|
+
def #{@state_machine.config.column}=(state_name)
|
|
34
|
+
if self.class.aasm.state_machine.config.no_direct_assignment
|
|
35
|
+
raise AASM::NoDirectAssignmentError.new(
|
|
36
|
+
'direct assignment of AASM column has been disabled (see AASM configuration for this class)'
|
|
37
|
+
)
|
|
38
|
+
else
|
|
39
|
+
super
|
|
40
|
+
end
|
|
33
41
|
end
|
|
34
|
-
|
|
42
|
+
)
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
# This method is both a getter and a setter
|
data/lib/aasm/core/event.rb
CHANGED
|
@@ -12,7 +12,7 @@ module AASM::Core
|
|
|
12
12
|
|
|
13
13
|
# from aasm4
|
|
14
14
|
@options = options # QUESTION: .dup ?
|
|
15
|
-
add_options_from_dsl(@options, [:after, :before, :error, :success], &block) if block
|
|
15
|
+
add_options_from_dsl(@options, [:after, :before, :error, :success, :after_commit], &block) if block
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# a neutered version of fire - it doesn't actually fire the event, it just
|
data/lib/aasm/core/state.rb
CHANGED
|
@@ -28,12 +28,12 @@ module AASM::Core
|
|
|
28
28
|
name.to_s
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def fire_callbacks(action, record)
|
|
31
|
+
def fire_callbacks(action, record, *args)
|
|
32
32
|
action = @options[action]
|
|
33
33
|
catch :halt_aasm_chain do
|
|
34
34
|
action.is_a?(Array) ?
|
|
35
|
-
action.each {|a| _fire_callbacks(a, record)} :
|
|
36
|
-
_fire_callbacks(action, record)
|
|
35
|
+
action.each {|a| _fire_callbacks(a, record, args)} :
|
|
36
|
+
_fire_callbacks(action, record, args)
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -66,12 +66,14 @@ module AASM::Core
|
|
|
66
66
|
self
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
def _fire_callbacks(action, record)
|
|
69
|
+
def _fire_callbacks(action, record, args)
|
|
70
70
|
case action
|
|
71
71
|
when Symbol, String
|
|
72
|
-
record.send(action)
|
|
72
|
+
arity = record.send(:method, action.to_sym).arity
|
|
73
|
+
record.send(action, *(arity < 0 ? args : args[0...arity]))
|
|
73
74
|
when Proc
|
|
74
|
-
action.
|
|
75
|
+
arity = action.arity
|
|
76
|
+
action.call(record, *(arity < 0 ? args : args[0...arity]))
|
|
75
77
|
end
|
|
76
78
|
end
|
|
77
79
|
|
data/lib/aasm/errors.rb
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
module AASM
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
class InvalidTransition < RuntimeError
|
|
4
|
+
attr_reader :object, :event_name
|
|
5
|
+
def initialize(object, event_name)
|
|
6
|
+
@object, @event_name = object, event_name
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def message
|
|
10
|
+
"Event '#{event_name}' cannot transition from '#{object.aasm.current_state}'"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
3
14
|
class UndefinedState < RuntimeError; end
|
|
4
15
|
class NoDirectAssignmentError < RuntimeError; end
|
|
5
16
|
end
|
|
@@ -10,7 +10,7 @@ module AASM
|
|
|
10
10
|
#
|
|
11
11
|
# Adds
|
|
12
12
|
#
|
|
13
|
-
#
|
|
13
|
+
# after_initialize :aasm_ensure_initial_state
|
|
14
14
|
#
|
|
15
15
|
# As a result, it doesn't matter when you define your methods - the following 2 are equivalent
|
|
16
16
|
#
|
|
@@ -166,7 +166,7 @@ module AASM
|
|
|
166
166
|
def aasm_ensure_initial_state
|
|
167
167
|
# checking via respond_to? does not work in Rails <= 3
|
|
168
168
|
# if respond_to?(self.class.aasm.attribute_name) && send(self.class.aasm.attribute_name).blank? # Rails 4
|
|
169
|
-
if
|
|
169
|
+
if attribute_names.include?(self.class.aasm.attribute_name.to_s) && send(self.class.aasm.attribute_name).blank?
|
|
170
170
|
aasm.enter_initial_state
|
|
171
171
|
end
|
|
172
172
|
end
|
|
@@ -176,7 +176,7 @@ module AASM
|
|
|
176
176
|
|
|
177
177
|
if success && options[:persist]
|
|
178
178
|
event = self.class.aasm.state_machine.events[name]
|
|
179
|
-
event.fire_callbacks(:after_commit, self)
|
|
179
|
+
event.fire_callbacks(:after_commit, self, *args)
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
success
|
|
@@ -187,7 +187,7 @@ module AASM
|
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
def aasm_validate_states
|
|
190
|
-
unless
|
|
190
|
+
unless aasm_skipping_validations
|
|
191
191
|
if aasm.current_state && !aasm.states.include?(aasm.current_state)
|
|
192
192
|
self.errors.add(AASM::StateMachine[self.class].config.column , "is invalid")
|
|
193
193
|
end
|
|
@@ -71,6 +71,9 @@ module AASM
|
|
|
71
71
|
elsif @klass.ancestors.map {|klass| klass.to_s}.include?("Mongoid::Document")
|
|
72
72
|
scope_options = lambda { @klass.send(:where, {@klass.aasm.attribute_name.to_sym => name.to_s}) }
|
|
73
73
|
@klass.send(:scope, name, scope_options)
|
|
74
|
+
elsif @klass.ancestors.map {|klass| klass.to_s}.include?("MongoMapper::Document")
|
|
75
|
+
conditions = { @klass.aasm.attribute_name.to_sym => name.to_s }
|
|
76
|
+
@klass.scope(name, lambda { @klass.where(conditions) })
|
|
74
77
|
end
|
|
75
78
|
end
|
|
76
79
|
end
|