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-1.3.0 lib/dynflow/stateful.rb
dynflow-1.2.3 lib/dynflow/stateful.rb
dynflow-1.2.2 lib/dynflow/stateful.rb
dynflow-1.2.1 lib/dynflow/stateful.rb
dynflow-1.2.0 lib/dynflow/stateful.rb
dynflow-1.2.0.pre1 lib/dynflow/stateful.rb
dynflow-1.1.6 lib/dynflow/stateful.rb
dynflow-1.1.5 lib/dynflow/stateful.rb
dynflow-1.1.4 lib/dynflow/stateful.rb
dynflow-1.1.3 lib/dynflow/stateful.rb
dynflow-1.1.2 lib/dynflow/stateful.rb
dynflow-1.1.1 lib/dynflow/stateful.rb
dynflow-1.1.0 lib/dynflow/stateful.rb
dynflow-1.0.5 lib/dynflow/stateful.rb
dynflow-1.0.4 lib/dynflow/stateful.rb
dynflow-1.0.3 lib/dynflow/stateful.rb
dynflow-1.0.2 lib/dynflow/stateful.rb
dynflow-1.0.1 lib/dynflow/stateful.rb
dynflow-1.0.0 lib/dynflow/stateful.rb
dynflow-0.8.37 lib/dynflow/stateful.rb