mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
27 lines
516 B
Ruby
27 lines
516 B
Ruby
module AASM
|
|
module SupportingClasses
|
|
class StateTransition
|
|
attr_reader :from, :to, :opts
|
|
|
|
def initialize(opts)
|
|
@from, @to, @guard = opts[:from], opts[:to], opts[:guard]
|
|
@opts = opts
|
|
end
|
|
|
|
def perform(obj)
|
|
case @guard
|
|
when Symbol, String
|
|
obj.send(@guard)
|
|
when Proc
|
|
@guard.call(obj)
|
|
else
|
|
true
|
|
end
|
|
end
|
|
|
|
def ==(obj)
|
|
@from == obj.from && @to == obj.to
|
|
end
|
|
end
|
|
end
|
|
end
|