1
0
Fork 0
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:
Cory Kaufman-Schofield 2017-06-06 16:53:23 -04:00 committed by Anil Kumar Maurya
parent 9c43e3903f
commit 217131cf36

View file

@ -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