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.7.6 lib/dynflow/stateful.rb
dynflow-0.7.5 lib/dynflow/stateful.rb
dynflow-0.7.4 lib/dynflow/stateful.rb
dynflow-0.7.3 lib/dynflow/stateful.rb
dynflow-0.7.2 lib/dynflow/stateful.rb
dynflow-0.7.1 lib/dynflow/stateful.rb
dynflow-0.7.0 lib/dynflow/stateful.rb
dynflow-0.6.2 lib/dynflow/stateful.rb
dynflow-0.6.1 lib/dynflow/stateful.rb
dynflow-0.6.0 lib/dynflow/stateful.rb
dynflow-0.5.1 lib/dynflow/stateful.rb
dynflow-0.5.0 lib/dynflow/stateful.rb
dynflow-0.4.1 lib/dynflow/stateful.rb
dynflow-0.4.0 lib/dynflow/stateful.rb
dynflow-0.3.0 lib/dynflow/stateful.rb
dynflow-0.2.0 lib/dynflow/stateful.rb