From f5cf3afb5b6c12ac81bdf40d232149065d7d83a2 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Fri, 1 Sep 2017 12:27:20 +0100 Subject: [PATCH] v3.1.0 --- CHANGELOG.md | 6 ++++++ LICENSE.txt | 2 +- README.md | 35 +++++++++++++++++++++-------------- lib/statesman/version.rb | 2 +- statesman.gemspec | 4 ++-- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0227a97..e0d962ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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* diff --git a/LICENSE.txt b/LICENSE.txt index c81e2536..d7a4b318 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2013 Harry Marr +Copyright (c) 2013-2017 GoCardless MIT License diff --git a/README.md b/README.md index e8d796c3..47334570 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -106,7 +114,6 @@ Order.first.state_machine.transition_to!(:cancelled) # => true/exception Order.in_state(:cancelled) # => [#] Order.not_in_state(:checking_out) # => [#] - ``` ## Persistence diff --git a/lib/statesman/version.rb b/lib/statesman/version.rb index 86375056..097a4d5c 100644 --- a/lib/statesman/version.rb +++ b/lib/statesman/version.rb @@ -1,3 +1,3 @@ module Statesman - VERSION = "3.0.0".freeze + VERSION = "3.1.0".freeze end diff --git a/statesman.gemspec b/statesman.gemspec index 8e9fa62d..db5ee278 100644 --- a/statesman.gemspec +++ b/statesman.gemspec @@ -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 = ["developers@gocardless.com"] - 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"