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

Small improvements to readme #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
Create a `state` field (or a custom name) for the module you want to apply a
state machine to, and ensure it's declared as part of your defstruct.

If using a Phoenix model, add it to the schema as a `string` and include it in
If using an Ecto struct, add a state field to the schema as a `:string` and include it in
the `changeset/2` function:

```elixir
Expand Down Expand Up @@ -67,7 +67,7 @@ Then import `Machinery` in this new module and declare states as arguments.
Machinery expects a `Keyword` as an argument with the keys `field`, `states`
and `transitions`.

- `field`: An atom representing your state field name (defaults to `state`)
- `field`: An atom representing your state field name (defaults to `:state`)
- `states`: A `List` of strings representing each state.
- `transitions`: A Map for each state and its allowed next state(s).

Expand All @@ -76,7 +76,7 @@ and `transitions`.
```elixir
defmodule YourProject.UserStateMachine do
use Machinery,
field: :custom_state_name, # Optional, default value is `:field`
field: :custom_state_name, # Optional, default value is `:state`
states: ["created", "partial", "completed", "canceled"],
transitions: %{
"created" => ["partial", "completed"],
Expand All @@ -93,7 +93,7 @@ state to a specific one.

To transition a struct to another state, call `Machinery.transition_to/3` or `Machinery.transition_to/4`.

### `Machinery.transition_to/3` or ``Machinery.transition_to/4`
### `Machinery.transition_to/3` or `Machinery.transition_to/4`

It takes the following arguments:

Expand Down Expand Up @@ -121,7 +121,7 @@ user = Accounts.get_user!(1)

## Persist State

To persist the struct and state transition, you declare a `persist/2` or `/3` *(in case you wanna access metadata passed on `transition_to/4`)*
To persist the struct and state transition, you declare a `persist/2` or `/3` *(in case you want to access metadata passed on `transition_to/4`)*
function in the state machine module.

This function will receive the unchanged `struct` as the first argument and a
Expand Down Expand Up @@ -151,7 +151,7 @@ end

## Logging Transitions

To log transitions, Machinery provides a `log_transition/2` or `/3` *(in case you wanna access metadata passed on `transition_to/4`)*
To log transitions, Machinery provides a `log_transition/2` or `/3` *(in case you want to access metadata passed on `transition_to/4`)*
callback that is called on every transition, after the `persist` function is executed.

This function receives the unchanged `struct` as the first
Expand Down Expand Up @@ -181,7 +181,7 @@ end

## Guard functions

Create guard conditions by adding `guard_transition/2` or `/3` *(in case you wanna access metadata passed on `transition_to/4`)*
Create guard conditions by adding `guard_transition/2` or `/3` *(in case you want to access metadata passed on `transition_to/4`)*
function signatures to the state machine module.
This function receives two arguments: the `struct` and a `string` of the state it
will transition to.
Expand Down Expand Up @@ -234,8 +234,8 @@ Machinery.transition_to(blocked_struct, TestStateMachineWithGuard, "completed")
You can also use before and after callbacks to handle desired side effects and
reactions to a specific state transition.

You can declare `before_transition/2` or `/3` *(in case you wanna access metadata passed on `transition_to/4`)*
and `after_transition/2` or `/3` *(in case you wanna access metadata passed on `transition_to/4`)*,
You can declare `before_transition/2` or `/3` *(in case you want to access metadata passed on `transition_to/4`)*
and `after_transition/2` or `/3` *(in case you want to access metadata passed on `transition_to/4`)*,
pattern matching the desired state you want to.

**Before and After callbacks should return the struct.**
Expand Down