Sha256: c9eec9879a858a857b9649b01fb381b2e12dd05a12aa611944514d05495aacb0

Contents?: true

Size: 908 Bytes

Versions: 76

Compression:

Stored size: 908 Bytes

Contents

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

76 entries across 76 versions & 1 rubygems

Version Path
dynflow-0.8.16 lib/dynflow/stateful.rb
dynflow-0.8.15 lib/dynflow/stateful.rb
dynflow-0.8.14 lib/dynflow/stateful.rb
dynflow-0.8.13 lib/dynflow/stateful.rb
dynflow-0.8.12 lib/dynflow/stateful.rb
dynflow-0.8.11 lib/dynflow/stateful.rb
dynflow-0.8.10 lib/dynflow/stateful.rb
dynflow-0.8.9 lib/dynflow/stateful.rb
dynflow-0.8.8 lib/dynflow/stateful.rb
dynflow-0.8.7 lib/dynflow/stateful.rb
dynflow-0.8.6 lib/dynflow/stateful.rb
dynflow-0.8.5 lib/dynflow/stateful.rb
dynflow-0.8.4 lib/dynflow/stateful.rb
dynflow-0.8.3 lib/dynflow/stateful.rb
dynflow-0.8.2 lib/dynflow/stateful.rb
dynflow-0.8.1 lib/dynflow/stateful.rb
dynflow-0.8.0 lib/dynflow/stateful.rb
dynflow-0.7.9 lib/dynflow/stateful.rb
dynflow-0.7.8 lib/dynflow/stateful.rb
dynflow-0.7.7 lib/dynflow/stateful.rb