2008-01-07 14:11:38 -05:00
|
|
|
module AASM
|
|
|
|
module SupportingClasses
|
|
|
|
class StateTransition
|
|
|
|
attr_reader :from, :to, :opts
|
|
|
|
|
|
|
|
def initialize(opts)
|
2008-06-04 00:44:25 -04:00
|
|
|
@from, @to, @guard, @on_transition = opts[:from], opts[:to], opts[:guard], opts[:on_transition]
|
2008-01-07 14:11:38 -05:00
|
|
|
@opts = opts
|
|
|
|
end
|
|
|
|
|
2008-02-21 10:46:06 -05:00
|
|
|
def perform(obj)
|
|
|
|
case @guard
|
|
|
|
when Symbol, String
|
|
|
|
obj.send(@guard)
|
|
|
|
when Proc
|
|
|
|
@guard.call(obj)
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-04 00:44:25 -04:00
|
|
|
def execute(obj, *args)
|
|
|
|
case @on_transition
|
|
|
|
when Symbol, String
|
|
|
|
obj.send(@on_transition, *args)
|
|
|
|
when Proc
|
|
|
|
@on_transition.call(obj, *args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-07 14:11:38 -05:00
|
|
|
def ==(obj)
|
|
|
|
@from == obj.from && @to == obj.to
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|