README.md in solidstate-0.1.0 vs README.md in solidstate-0.2.0
- old
+ new
@@ -48,32 +48,32 @@
class Subscriber < ActiveRecord::Base
include SolidState
states :inactive, :active, :unsubscribed, :disabled do
- transitions :from => :inactive, :to => :active
- transitions :from => :active, :to => [:unsubscribed, :disabled]
- transitions :from => :unsubscribed, :to => :active
+ transitions from: :inactive, to: :active
+ transitions from: :active, to: [:unsubscribed, :disabled]
+ transitions from: :unsubscribed, to: :active
end
end
s = Subscriber.new
- s.state # => 'inactive'
+ s.state # => 'inactive'
# since we declared transitions, we can now call #{state}! which
# checks whether the instance can transition to that state and
# if so, sets the new state and optionally saves the record.
- s.active! # => true
+ s.active! # => true
s.inactive! # => raises InvalidTransitionError
# this also works outside transition methods, of course.
- s.reload # => true
- s.active? # => true
+ s.reload # => true
+ s.active? # => true
s.state = 'inactive'
- s.valid? # => false
+ s.valid? # => false
# the last trick this library does is that it optionally lets you
# declare callback methods that are called whenever a transition
# method succeeds. just define a method called #once_[state] in
# your model.