As a side benefit, fix an (non-user-visible) bug in display_s5(). Also fixed a bug where removing orphaned pages did not expire cached summary pages.
41 lines
830 B
Ruby
41 lines
830 B
Ruby
module ActiveModel
|
|
module StateMachine
|
|
class StateTransition
|
|
attr_reader :from, :to, :options
|
|
|
|
def initialize(opts)
|
|
@from, @to, @guard, @on_transition = opts[:from], opts[:to], opts[:guard], opts[:on_transition]
|
|
@options = opts
|
|
end
|
|
|
|
def perform(obj)
|
|
case @guard
|
|
when Symbol, String
|
|
obj.send(@guard)
|
|
when Proc
|
|
@guard.call(obj)
|
|
else
|
|
true
|
|
end
|
|
end
|
|
|
|
def execute(obj, *args)
|
|
case @on_transition
|
|
when Symbol, String
|
|
obj.send(@on_transition, *args)
|
|
when Proc
|
|
@on_transition.call(obj, *args)
|
|
end
|
|
end
|
|
|
|
def ==(obj)
|
|
@from == obj.from && @to == obj.to
|
|
end
|
|
|
|
def from?(value)
|
|
@from == value
|
|
end
|
|
end
|
|
end
|
|
end
|