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.36 lib/dynflow/stateful.rb
dynflow-0.8.35 lib/dynflow/stateful.rb
dynflow-0.8.34 lib/dynflow/stateful.rb
dynflow-0.8.33 lib/dynflow/stateful.rb
dynflow-0.8.32 lib/dynflow/stateful.rb
dynflow-0.8.31 lib/dynflow/stateful.rb
dynflow-0.8.30 lib/dynflow/stateful.rb
dynflow-0.8.29 lib/dynflow/stateful.rb
dynflow-0.8.28 lib/dynflow/stateful.rb
dynflow-0.8.27 lib/dynflow/stateful.rb
dynflow-0.8.26 lib/dynflow/stateful.rb
dynflow-0.8.25 lib/dynflow/stateful.rb
dynflow-0.8.24 lib/dynflow/stateful.rb
dynflow-0.8.23 lib/dynflow/stateful.rb
dynflow-0.8.22 lib/dynflow/stateful.rb
dynflow-0.8.21 lib/dynflow/stateful.rb
dynflow-0.8.20 lib/dynflow/stateful.rb
dynflow-0.8.19 lib/dynflow/stateful.rb
dynflow-0.8.18 lib/dynflow/stateful.rb
dynflow-0.8.17 lib/dynflow/stateful.rb