Skip to content

Commit

Permalink
Merge pull request #269 from gocardless/v3.1.0
Browse files Browse the repository at this point in the history
v3.1.0
  • Loading branch information
Tim Rogers authored Sep 1, 2017
2 parents 50d43ad + f5cf3af commit dd4f4e6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v3.1.0, 1 September 2017

- Add support for Rails 5.0.x and 5.1.x (patch by [@kenchan0130](https://github.com/kenchan0130) and [@timrogers](https://github.com/timrogers))
- Run tests in CircleCI instead of TravisCI (patch by [@timrogers](https://github.com/timrogers))
- Update Rubocop and fix offences (patch by [@timrogers](https://github.com/timrogers))

## v3.0.0, 3 July 2017

*Breaking changes*
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013 Harry Marr
Copyright (c) 2013-2017 GoCardless

MIT License

Expand Down
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ include JSON metadata set during a transition.
- Database indices are used to offer database-level transaction duplication
protection.

## TL;DR Usage
## Installation

To get started, just add Statesman to your `Gemfile`, and then run `bundle`:

```ruby
gem 'statesman', '~> 3.1.0'
```

## Usage

First, create a state machine based on `Statesman::Machine`:

#######################
# State Machine Class #
#######################
```ruby
class OrderStateMachine
include Statesman::Machine

Expand Down Expand Up @@ -63,10 +69,11 @@ class OrderStateMachine
MailerService.order_confirmation(order).deliver
end
end
```

Then, link it to your model:

##############
# Your Model #
##############
```ruby
class Order < ActiveRecord::Base
include Statesman::Adapters::ActiveRecordQueries

Expand All @@ -85,19 +92,20 @@ class Order < ActiveRecord::Base
end
private_class_method :initial_state
end
```

####################
# Transition Model #
####################
Next, you'll need to create a further model to represent state transitions:

```ruby
class OrderTransition < ActiveRecord::Base
include Statesman::Adapters::ActiveRecordTransition

belongs_to :order, inverse_of: :order_transitions
end

########################
# Example method calls #
########################
Now, you can start working with your state machine:

```ruby
Order.first.state_machine.current_state # => "pending"
Order.first.state_machine.allowed_transitions # => ["checking_out", "cancelled"]
Order.first.state_machine.can_transition_to?(:cancelled) # => true/false
Expand All @@ -106,7 +114,6 @@ Order.first.state_machine.transition_to!(:cancelled) # => true/exception
Order.in_state(:cancelled) # => [#<Order id: "123">]
Order.not_in_state(:checking_out) # => [#<Order id: "123">]

```

## Persistence
Expand Down
2 changes: 1 addition & 1 deletion lib/statesman/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Statesman
VERSION = "3.0.0".freeze
VERSION = "3.1.0".freeze
end
4 changes: 2 additions & 2 deletions statesman.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require 'statesman/version'
Gem::Specification.new do |spec|
spec.name = "statesman"
spec.version = Statesman::VERSION
spec.authors = ["Harry Marr", "Andy Appleton"]
spec.authors = ["GoCardless"]
spec.email = ["[email protected]"]
spec.description = 'A statesmanlike state machine library'
spec.description = 'A statesman-like state machine library'
spec.summary = spec.description
spec.homepage = "https://github.com/gocardless/statesman"
spec.license = "MIT"
Expand Down

0 comments on commit dd4f4e6

Please sign in to comment.