2013-08-20 15:47:01 -04:00
# AASM - Ruby state machines
2014-12-01 14:47:27 -05:00
[![Gem Version ](https://badge.fury.io/rb/aasm.svg )](http://badge.fury.io/rb/aasm)
2014-03-21 05:15:13 -04:00
[![Build Status ](https://travis-ci.org/aasm/aasm.svg?branch=master )](https://travis-ci.org/aasm/aasm)
2014-12-01 14:47:27 -05:00
[![Code Climate ](https://codeclimate.com/github/aasm/aasm/badges/gpa.svg )](https://codeclimate.com/github/aasm/aasm)
[![Coverage Status ](https://img.shields.io/coveralls/aasm/aasm.svg )](https://coveralls.io/r/aasm/aasm?branch=master)
2008-02-22 18:23:19 -05:00
2008-03-04 18:59:58 -05:00
This package contains AASM, a library for adding finite state machines to Ruby classes.
2008-02-22 18:23:19 -05:00
2012-10-26 04:32:51 -04:00
AASM started as the *acts_as_state_machine* plugin but has evolved into a more generic library
2012-01-16 11:11:51 -05:00
that no longer targets only ActiveRecord models. It currently provides adapters for
[ActiveRecord ](http://api.rubyonrails.org/classes/ActiveRecord/Base.html ) and
2012-10-25 05:38:05 -04:00
[Mongoid ](http://mongoid.org/ ), but it can be used for any Ruby class, no matter what
parent class it has (if any).
2014-11-15 11:52:03 -05:00
## Upgrade from version 3 to 4
Take a look at the [README_FROM_VERSION_3_TO_4 ](https://github.com/aasm/aasm/blob/master/README_FROM_VERSION_3_TO_4.md ) for details how to switch from version 3.x to 4.0 of _AASM_ .
2012-10-25 05:38:05 -04:00
## Usage
2012-10-26 04:32:51 -04:00
Adding a state machine is as simple as including the AASM module and start defining
**states** and **events** together with their **transitions** :
2012-10-25 05:38:05 -04:00
```ruby
class Job
include AASM
aasm do
state :sleeping, :initial => true
state :running
2012-10-26 04:32:51 -04:00
state :cleaning
2012-10-25 05:38:05 -04:00
event :run do
transitions :from => :sleeping, :to => :running
end
2012-10-26 04:32:51 -04:00
event :clean do
transitions :from => :running, :to => :cleaning
end
2012-10-25 05:38:05 -04:00
event :sleep do
2012-10-26 04:32:51 -04:00
transitions :from => [:running, :cleaning], :to => :sleeping
2012-10-25 05:38:05 -04:00
end
end
end
```
2012-10-26 04:32:51 -04:00
This provides you with a couple of public methods for instances of the class `Job` :
2012-10-25 05:38:05 -04:00
```ruby
job = Job.new
job.sleeping? # => true
job.may_run? # => true
job.run
job.running? # => true
job.sleeping? # => false
job.may_run? # => false
job.run # => raises AASM::InvalidTransition
```
2012-10-26 04:32:51 -04:00
If you don't like exceptions and prefer a simple `true` or `false` as response, tell
AASM not to be *whiny* :
2012-10-25 05:38:05 -04:00
```ruby
class Job
...
aasm :whiny_transitions => false do
...
end
end
job.running? # => true
job.may_run? # => false
job.run # => false
```
2013-11-19 13:58:10 -05:00
When firing an event, you can pass a block to the method, it will be called only if
the transition succeeds :
```ruby
job.run do
job.user.notify_job_ran # Will be called if job.may_run? is true
end
```
2012-10-25 05:38:05 -04:00
### Callbacks
2012-10-26 04:32:51 -04:00
You can define a number of callbacks for your transitions. These methods will be
called, when certain criteria are met, like entering a particular state:
2012-10-25 05:38:05 -04:00
```ruby
2012-10-26 04:32:51 -04:00
class Job
2012-10-25 05:38:05 -04:00
include AASM
2012-10-26 04:32:51 -04:00
aasm do
state :sleeping, :initial => true, :before_enter => :do_something
2012-10-25 05:38:05 -04:00
state :running
2014-09-12 08:30:36 -04:00
event :run, :after => :notify_somebody do
transitions :from => :sleeping, :to => :running, :after => Proc.new {|*args| set_process(*args) } do
before do
log('Preparing to run')
end
end
2012-10-25 05:38:05 -04:00
end
event :sleep do
2013-02-02 03:22:52 -05:00
after do
...
end
2013-02-21 03:16:08 -05:00
error do |e|
...
end
2012-10-25 05:38:05 -04:00
transitions :from => :running, :to => :sleeping
end
end
2013-02-02 02:10:45 -05:00
def set_process(name)
...
end
2012-10-26 04:32:51 -04:00
def do_something
...
end
2014-01-29 15:43:04 -05:00
def notify_somebody(user)
2012-10-26 04:32:51 -04:00
...
end
2012-10-25 05:38:05 -04:00
end
```
2012-10-26 04:32:51 -04:00
In this case `do_something` is called before actually entering the state `sleeping` ,
2014-01-29 15:43:04 -05:00
while `notify_somebody` is called after the transition `run` (from `sleeping` to `running` )
2012-10-26 04:32:51 -04:00
is finished.
Here you can see a list of all possible callbacks, together with their order of calling:
2012-10-25 05:38:05 -04:00
```ruby
2014-09-09 17:02:11 -04:00
begin
event before
2014-11-19 17:34:39 -05:00
event guards
transition guards
2014-09-09 17:02:11 -04:00
old_state before_exit
old_state exit
new_state before_enter
new_state enter
...update state...
2014-09-12 08:30:36 -04:00
transition after
2014-09-09 17:02:11 -04:00
event success # if persist successful
old_state after_exit
new_state after_enter
event after
rescue
event error
end
2012-10-25 05:38:05 -04:00
```
2013-02-02 02:10:45 -05:00
Also, you can pass parameters to events:
```ruby
job = Job.new
job.run(:running, :defragmentation)
```
2014-07-21 19:49:46 -04:00
In this case the `set_process` would be called with `:defragmentation` argument.
2013-02-02 02:10:45 -05:00
2014-08-06 13:42:28 -04:00
Note that when passing arguments to a state transition, the first argument must be the desired end state. In the above example, we wish to transition to `:running` state and run the callback with `:defragmentation` argument. You can also pass in `nil` as the desired end state, and AASM will try to transition to the first end state defined for that event.
2013-02-02 02:10:45 -05:00
2013-02-21 15:35:06 -05:00
In case of an error during the event processing the error is rescued and passed to `:error`
callback, which can handle it or re-raise it for further propagation.
2013-02-21 03:16:08 -05:00
2014-11-27 01:55:34 -05:00
During the transition's `:after` callback (and reliably only then) you can access the
2014-01-27 15:51:38 -05:00
originating state (the from-state) and the target state (the to state), like this:
```ruby
def set_process(name)
logger.info "from #{aasm.from_state} to #{aasm.to_state}"
end
```
2014-09-12 05:42:01 -04:00
#### The current event triggered
While running the callbacks you can easily retrieve the name of the event triggered
by using `aasm.current_event` :
```ruby
# taken the example callback from above
def do_something
puts "triggered #{aasm.current_event}"
end
```
and then
```ruby
job = Job.new
# without bang
job.sleep # => triggered :sleep
# with bang
job.sleep! # => triggered :sleep!
```
2012-10-26 04:32:51 -04:00
### Guards
2012-10-25 05:38:05 -04:00
2012-10-26 04:32:51 -04:00
Let's assume you want to allow particular transitions only if a defined condition is
given. For this you can set up a guard per transition, which will run before actually
running the transition. If the guard returns `false` the transition will be
denied (raising `AASM::InvalidTransition` or returning `false` itself):
2012-10-25 05:38:05 -04:00
2012-10-26 04:32:51 -04:00
```ruby
2014-09-12 08:30:36 -04:00
class Cleaner
2012-10-26 04:32:51 -04:00
include AASM
2012-10-24 04:03:09 -04:00
2012-10-26 04:32:51 -04:00
aasm do
2014-09-12 08:30:36 -04:00
state :idle, :initial => true
2012-10-26 04:32:51 -04:00
state :cleaning
2008-02-22 18:23:19 -05:00
2012-10-26 04:32:51 -04:00
event :clean do
2014-09-12 08:30:36 -04:00
transitions :from => :idle, :to => :cleaning, :guard => :cleaning_needed?
2012-10-26 04:32:51 -04:00
end
2008-02-22 18:23:19 -05:00
2014-09-12 08:30:36 -04:00
event :clean_if_needed do
transitions :from => :idle, :to => :cleaning do
guard do
cleaning_needed?
end
end
transitions :from => :idle, :to => :idle
2012-10-26 04:32:51 -04:00
end
end
2008-02-22 18:23:19 -05:00
2012-10-26 07:12:00 -04:00
def cleaning_needed?
2012-10-26 04:32:51 -04:00
false
end
end
2011-08-31 15:56:09 -04:00
2014-09-12 08:30:36 -04:00
job = Cleaner.new
job.may_clean? # => false
job.clean # => raises AASM::InvalidTransition
job.may_clean_if_needed? # => true
job.clean_if_needed! # idle
2012-10-26 04:32:51 -04:00
```
2008-03-04 18:59:58 -05:00
2014-01-24 05:12:43 -05:00
You can even provide a number of guards, which all have to succeed to proceed
```ruby
2014-01-24 06:02:22 -05:00
def walked_the_dog?; ...; end
2014-01-24 05:12:43 -05:00
event :sleep do
transitions :from => :running, :to => :sleeping, :guards => [:cleaning_needed?, :walked_the_dog?]
end
```
2008-03-04 18:59:58 -05:00
2014-07-17 09:23:54 -04:00
If you want to provide guards for all transitions within an event, you can use event guards
2014-01-24 06:02:22 -05:00
```ruby
event :sleep, :guards => [:walked_the_dog?] do
transitions :from => :running, :to => :sleeping, :guards => [:cleaning_needed?]
transitions :from => :cleaning, :to => :sleeping
end
```
2014-11-14 12:08:34 -05:00
If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as well:
```ruby
event :clean do
2014-11-22 22:13:14 -05:00
transitions :from => :running, :to => :cleaning, :if => :cleaning_needed?
2014-11-14 12:08:34 -05:00
end
event :sleep do
2014-11-22 22:13:14 -05:00
transitions :from => :running, :to => :sleeping, :unless => :cleaning_needed?
2014-11-14 12:08:34 -05:00
end
end
```
2014-10-07 15:50:20 -04:00
### Transitions
In the event of having multiple transitions for an event, the first transition that successfully completes will stop other transitions in the same event from being processed.
```ruby
require 'aasm'
class Job
include AASM
aasm do
state :stage1, :initial => true
state :stage2
state :stage3
state :completed
event :stage1_completed do
transitions from: :stage1, to: :stage3, guard: :stage2_completed?
transitions from: :stage1, to: :stage2
end
end
def stage2_completed?
true
end
end
job = Job.new
job.stage1_completed
job.aasm.current_state # stage3
```
2012-10-26 04:32:51 -04:00
### ActiveRecord
2008-03-04 18:59:58 -05:00
2012-10-26 04:32:51 -04:00
AASM comes with support for ActiveRecord and allows automatical persisting of the object's
state in the database.
2009-10-23 16:33:01 -04:00
2012-10-26 04:32:51 -04:00
```ruby
class Job < ActiveRecord::Base
include AASM
2008-04-29 20:51:12 -04:00
2012-10-26 04:32:51 -04:00
aasm do # default column: aasm_state
state :sleeping, :initial => true
state :running
2011-10-23 15:21:51 -04:00
2012-10-26 04:32:51 -04:00
event :run do
transitions :from => :sleeping, :to => :running
end
2011-10-23 15:21:51 -04:00
2012-10-26 04:32:51 -04:00
event :sleep do
transitions :from => :running, :to => :sleeping
end
end
2008-03-04 18:59:58 -05:00
2012-10-26 04:32:51 -04:00
end
2011-08-31 15:50:59 -04:00
```
2008-03-04 18:59:58 -05:00
2012-10-26 04:32:51 -04:00
You can tell AASM to auto-save the object or leave it unsaved
2012-01-16 11:27:15 -05:00
2012-10-26 04:32:51 -04:00
```ruby
job = Job.new
job.run # not saved
job.run! # saved
```
2008-03-04 18:59:58 -05:00
2012-10-26 04:32:51 -04:00
Saving includes running all validations on the `Job` class. If you want make sure
the state gets saved without running validations (and thereby maybe persisting an
invalid object state), simply tell AASM to skip the validations:
2008-03-04 18:59:58 -05:00
2011-08-31 15:50:59 -04:00
```ruby
2012-10-26 04:32:51 -04:00
class Job < ActiveRecord::Base
2011-11-26 15:11:57 -05:00
include AASM
2008-03-04 18:59:58 -05:00
2012-10-26 04:32:51 -04:00
aasm :skip_validation_on_save => true do
state :sleeping, :initial => true
state :running
2008-03-04 18:59:58 -05:00
2012-10-26 04:32:51 -04:00
event :run do
transitions :from => :sleeping, :to => :running
2008-03-04 18:59:58 -05:00
end
2012-10-26 04:32:51 -04:00
event :sleep do
transitions :from => :running, :to => :sleeping
2008-03-04 18:59:58 -05:00
end
end
2011-11-26 15:11:57 -05:00
end
2011-08-31 15:50:59 -04:00
```
2008-03-04 18:59:58 -05:00
2014-05-18 08:21:35 -04:00
If you want to make sure that the _AASM_ column for storing the state is not directly assigned,
configure _AASM_ to not allow direct assignment, like this:
```ruby
class Job < ActiveRecord::Base
include AASM
aasm :no_direct_assignment => true do
state :sleeping, :initial => true
state :running
event :run do
transitions :from => :sleeping, :to => :running
end
end
end
```
resulting in this:
```ruby
job = Job.create
job.aasm_state # => 'sleeping'
job.aasm_state = :running # => raises AASM::NoDirectAssignmentError
job.aasm_state # => 'sleeping'
```
2014-05-10 05:02:11 -04:00
#### ActiveRecord enums
You can use
[enumerations ](http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html )
in Rails 4.1+ for your state column:
```ruby
class Job < ActiveRecord::Base
include AASM
2014-07-08 06:46:42 -04:00
enum state: {
2014-05-10 05:02:11 -04:00
sleeping: 5,
running: 99
}
2014-05-15 04:04:57 -04:00
aasm :column => :state, :enum => true do
2014-05-10 05:02:11 -04:00
state :sleeping, :initial => true
state :running
end
end
```
2014-05-15 04:04:57 -04:00
You can explicitly pass the name of the method which provides access
to the enumeration mapping as a value of ```enum```, or you can simply
2014-05-15 04:09:22 -04:00
set it to ```true```. In the latter case AASM will try to use
pluralized column name to access possible enum states.
2014-05-15 04:04:57 -04:00
Furthermore, if your column has integer type (which is normally the
2014-05-15 04:09:22 -04:00
case when you're working with Rails enums), you can omit ```:enum```
setting --- AASM auto-detects this situation and enabled enum
support. If anything goes wrong, you can disable enum functionality
2014-05-15 04:10:22 -04:00
and fall back to the default behavior by setting ```:enum```
to ```false```.
2014-05-10 05:02:11 -04:00
2014-05-04 06:12:04 -04:00
### Sequel
2014-05-05 15:54:33 -04:00
AASM also supports [Sequel ](http://sequel.jeremyevans.net/ ) besides _ActiveRecord_ and _Mongoid_ .
2014-05-04 06:12:04 -04:00
```ruby
class Job < Sequel::Model
include AASM
aasm do # default column: aasm_state
...
end
end
```
2014-05-05 15:54:33 -04:00
However it's not yet as feature complete as _ActiveRecord_ . For example, there are
scopes defined yet. See [Automatic Scopes ](#automatic-scopes ).
2014-05-04 06:12:04 -04:00
2013-08-29 11:05:43 -04:00
### Mongoid
AASM also supports persistence to Mongodb if you're using Mongoid. Make sure
to include Mongoid::Document before you include AASM.
```ruby
class Job
include Mongoid::Document
include AASM
2013-12-02 06:19:42 -05:00
field :aasm_state
2013-08-29 11:05:43 -04:00
aasm do
...
end
end
```
2013-01-06 17:42:05 -05:00
### Automatic Scopes
AASM will automatically create scope methods for each state in the model.
```ruby
class Job < ActiveRecord::Base
include AASM
aasm do
state :sleeping, :initial => true
state :running
state :cleaning
end
2014-04-30 23:17:15 -04:00
def self.sleeping
2014-09-16 09:28:45 -04:00
"This method name is already in use"
2013-01-06 17:42:05 -05:00
end
end
```
```ruby
class JobsController < ApplicationController
def index
2014-05-03 06:24:30 -04:00
@running_jobs = Job.running
@recent_cleaning_jobs = Job.cleaning.where('created_at >= ?', 3.days.ago)
2013-01-06 17:42:05 -05:00
2014-09-16 09:28:45 -04:00
# @sleeping_jobs = Job.sleeping #=> "This method name is already in use"
2013-01-06 17:42:05 -05:00
end
end
```
2013-08-06 10:55:32 -04:00
If you don't need scopes (or simply don't want them), disable their creation when
defining the `AASM` states, like this:
```ruby
class Job < ActiveRecord::Base
include AASM
aasm :create_scopes => false do
state :sleeping, :initial => true
state :running
state :cleaning
end
end
```
2012-10-26 04:32:51 -04:00
### Transaction support
Since version *3.0.13* AASM supports ActiveRecord transactions. So whenever a transition
callback or the state update fails, all changes to any database record are rolled back.
2013-08-29 11:05:43 -04:00
Mongodb does not support transactions.
2012-10-26 04:32:51 -04:00
2013-10-24 09:29:18 -04:00
If you want to make sure a depending action happens only after the transaction is committed,
use the `after_commit` callback, like this:
```ruby
class Job < ActiveRecord::Base
include AASM
aasm do
state :sleeping, :initial => true
2014-03-17 16:58:44 -04:00
state :running
2013-10-24 09:29:18 -04:00
2014-03-17 16:58:44 -04:00
event :run, :after_commit => :notify_about_running_job do
2013-10-24 09:29:18 -04:00
transitions :from => :sleeping, :to => :running
end
end
def notify_about_running_job
...
end
end
```
2014-01-22 15:28:40 -05:00
If you want to encapsulate state changes within an own transaction, the behavior
of this nested transaction might be confusing. Take a look at
[ActiveRecord Nested Transactions ](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html )
if you want to know more about this. Nevertheless, AASM by default requires a new transaction
`transaction(:requires_new => true)` . You can override this behavior by changing
the configuration
```ruby
class Job < ActiveRecord::Base
include AASM
aasm :requires_new_transaction => false do
...
end
...
end
```
which then leads to `transaction(:requires_new => false)` , the Rails default.
2012-10-26 04:32:51 -04:00
### Column name & migration
2009-02-26 12:06:43 -05:00
2012-10-26 04:32:51 -04:00
As a default AASM uses the column `aasm_state` to store the states. You can override
this by defining your favorite column name, using `:column` like this:
2009-02-26 12:06:43 -05:00
2011-08-31 15:50:59 -04:00
```ruby
2012-10-26 04:32:51 -04:00
class Job < ActiveRecord::Base
include AASM
aasm :column => 'my_state' do
...
2009-02-26 12:06:43 -05:00
end
2012-10-26 04:32:51 -04:00
end
2011-08-31 15:50:59 -04:00
```
2009-02-26 12:06:43 -05:00
2012-10-26 04:32:51 -04:00
Whatever column name is used, make sure to add a migration to provide this column
(of type `string` ):
2011-09-04 11:59:55 -04:00
```ruby
2012-10-26 04:32:51 -04:00
class AddJobState < ActiveRecord::Migration
def self.up
add_column :jobs, :aasm_state, :string
end
def self.down
2013-04-03 11:43:32 -04:00
remove_column :jobs, :aasm_state
2011-09-04 11:59:55 -04:00
end
2012-10-26 04:32:51 -04:00
end
2011-09-04 11:59:55 -04:00
```
2013-10-24 09:29:18 -04:00
### Inspection
2013-04-28 10:42:48 -04:00
2014-10-13 17:24:00 -04:00
AASM supports a couple of methods to find out which states or events are provided or permitted.
2013-04-28 10:42:48 -04:00
2014-10-10 17:41:59 -04:00
Given this `Job` class:
2013-04-28 10:42:48 -04:00
```ruby
2014-10-10 17:41:59 -04:00
# show all states
Job.aasm.states.map(& :name)
2013-04-28 10:42:48 -04:00
=> [:sleeping, :running, :cleaning]
2014-10-10 17:41:59 -04:00
job = Job.new
2014-10-13 17:24:00 -04:00
# show all permitted (reachable / possible) states
job.aasm.states(:permitted => true).map(& :name)
2013-04-28 11:46:16 -04:00
=> [:running]
job.run
2014-10-13 17:24:00 -04:00
job.aasm.states(:permitted => true).map(& :name)
2013-04-28 11:46:16 -04:00
=> [:cleaning, :sleeping]
2014-10-10 17:41:59 -04:00
# show all possible (triggerable) events (allowed by transitions)
2014-10-12 09:46:11 -04:00
job.aasm.events.map(& :name)
2014-10-10 17:41:59 -04:00
=> [:sleep]
2013-04-28 10:42:48 -04:00
```
2013-04-28 11:49:59 -04:00
## <a id="installation">Installation ##
2012-10-26 04:32:51 -04:00
### Manually from RubyGems.org ###
```sh
% gem install aasm
```
### Or if you are using Bundler ###
2012-01-16 11:27:15 -05:00
```ruby
2012-10-26 04:32:51 -04:00
# Gemfile
gem 'aasm'
2012-01-16 11:27:15 -05:00
```
2012-10-26 04:32:51 -04:00
### Building your own gems ###
2012-01-16 11:27:15 -05:00
2012-10-26 04:32:51 -04:00
```sh
% rake build
% sudo gem install pkg/aasm-x.y.z.gem
```
2012-01-16 11:27:15 -05:00
2012-10-26 04:32:51 -04:00
## Latest changes ##
2011-09-04 11:59:55 -04:00
2013-11-30 18:35:45 -05:00
Take a look at the [CHANGELOG ](https://github.com/aasm/aasm/blob/master/CHANGELOG.md ) for details about recent changes to the current version.
2011-11-25 18:11:30 -05:00
2013-02-25 22:26:45 -05:00
## Questions? ##
Feel free to
* [create an issue on GitHub ](https://github.com/aasm/aasm/issues )
* [ask a question on StackOverflow ](http://stackoverflow.com ) (tag with `aasm` )
* send us a tweet [@aasm ](http://twitter.com/aasm )
2011-11-25 18:11:30 -05:00
2013-11-30 18:35:45 -05:00
## Maintainers ##
2011-11-25 18:11:30 -05:00
2013-11-30 18:35:45 -05:00
* [Scott Barron ](https://github.com/rubyist ) (2006– 2009, original author)
* [Travis Tilley ](https://github.com/ttilley ) (2009– 2011)
* [Thorsten Böttger ](http://github.com/alto ) (since 2011)
2008-03-04 18:59:58 -05:00
2011-08-31 15:50:59 -04:00
## Warranty ##
2008-03-04 18:59:58 -05:00
This software is provided "as is" and without any express or
implied warranties, including, without limitation, the implied
warranties of merchantibility and fitness for a particular
purpose.
2011-11-25 18:11:30 -05:00
## License ##
2013-11-30 18:35:45 -05:00
Copyright (c) 2006-2014 Scott Barron
2011-11-25 18:11:30 -05:00
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.