Sha256: 5b2e471efd7c6c8d7da07cefe31a9a0fd7f50ddd8717a8faddfcd6c6afdd1346
Contents?: true
Size: 938 Bytes
Versions: 25
Compression:
Stored size: 938 Bytes
Contents
# frozen_string_literal: true module Dynflow module Stateful def self.included(base) base.extend ClassMethods end module ClassMethods def states raise NotImplementedError end def state_transitions raise NotImplementedError end end def states self.class.states end def state_transitions self.class.state_transitions end attr_reader :state def state=(state) set_state state, false end def set_state(state, skip_transition_check) state = state.to_sym if state.is_a?(String) && states.map(&:to_s).include?(state) raise "unknown state #{state}" unless states.include? state unless self.state.nil? || skip_transition_check || state_transitions.fetch(self.state).include?(state) raise "invalid state transition #{self.state} >> #{state} in #{self}" end @state = state end end end
Version data entries
25 entries across 25 versions & 1 rubygems