Sha256: 1d94cfab43cad04a09620b5daa869b5800cb59a25d82d75c9075fbf27301eadf
Contents?: true
Size: 954 Bytes
Versions: 1
Compression:
Stored size: 954 Bytes
Contents
module Multiflow class IncorrectTransition < Exception; end class Transition attr_reader :from, :to, :if, :decide def initialize(args) @from = [args[:from]].flatten @to = args[:to] @if = args[:if] @decide = args[:decide] end def can_transition?(base) return true unless @if execute_action(@if, base) end def find_to_state(base) raise IncorrectTransition.new("Array of destinations and no decision") if @to.is_a?(Array) && @decide.nil? return @to unless @to.is_a?(Array) to = execute_action(@decide, base) raise NoStateFound.new("Decision did not return a state that was set in the 'to' argument") unless @to.include?(to) to end private def execute_action(action, base) case action when Symbol, String base.send(action) when Proc action.call(base) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
multiflow-1.0.0 | lib/multiflow/transition.rb |