Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for namespaces #472

Merged
merged 1 commit into from Aug 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 48 additions & 2 deletions README.md
Expand Up @@ -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

Expand Down