mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Add documentation for namespaces
This commit is contained in:
parent
9c43e3903f
commit
217131cf36
1 changed files with 48 additions and 2 deletions
50
README.md
50
README.md
|
@ -425,10 +425,56 @@ simple.aasm(:work).current
|
|||
|
||||
```
|
||||
|
||||
_AASM_ doesn't prohibit to define the same event in more than one state machine. The
|
||||
latest definition "wins" and overrides previous definitions. Nonetheless, a warning is issued:
|
||||
#### Handling naming conflicts between multiple state machines
|
||||
|
||||
_AASM_ doesn't prohibit to define the same event in more than one state
|
||||
machine. If no namespace is provided, the latest definition "wins" and
|
||||
overrides previous definitions. Nonetheless, a warning is issued:
|
||||
`SimpleMultipleExample: overriding method 'run'!`.
|
||||
|
||||
Alternatively, you can provide a namespace for each state machine:
|
||||
|
||||
```ruby
|
||||
class NamespacedMultipleExample
|
||||
include AASM
|
||||
aasm(:status) do
|
||||
state :unapproved, :initial => true
|
||||
state :approved
|
||||
|
||||
event :approve do
|
||||
transitions :from => :unapproved, :to => :approved
|
||||
end
|
||||
|
||||
event :unapprove do
|
||||
transitions :from => :approved, :to => :unapproved
|
||||
end
|
||||
end
|
||||
|
||||
aasm(:review_status, namespace: :review) do
|
||||
state :unapproved, :initial => true
|
||||
state :approved
|
||||
|
||||
event :approve do
|
||||
transitions :from => :unapproved, :to => :approved
|
||||
end
|
||||
|
||||
event :unapprove do
|
||||
transitions :from => :approved, :to => :unapproved
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespaced = NamespacedMultipleExample.new
|
||||
|
||||
namespaced.aasm(:status).current_state
|
||||
# => :unapproved
|
||||
namespaced.aasm(:review_status).current_state
|
||||
# => :unapproved
|
||||
namespaced.approve_review
|
||||
namespaced.aasm(:review_status).current_state
|
||||
# => :approved
|
||||
```
|
||||
|
||||
All _AASM_ class- and instance-level `aasm` methods accept a state machine selector.
|
||||
So, for example, to use inspection on a class level, you have to use
|
||||
|
||||
|
|
Loading…
Reference in a new issue