Sha256: 4e1c5b7696231d4190a1e4f9867aa9ce7c39a3199d6e7288fac61af9455af18a

Contents?: true

Size: 979 Bytes

Versions: 1

Compression:

Stored size: 979 Bytes

Contents

module Action
  class State
    module ClassMethods
      def sequence_status sequence
        chunks = sequence.chunk{|status|status}
        statuses = chunks.map(&:first)
        chunks = chunks.map(&:last)
        current = nil
        case chunks.count
        when 0
          return :empty
        when 1
          status = statuses.first
          return status if [:done, :planned].include?(status)
          current = 0
        when 2
          current = if statuses.first == :done
                      1
                    elsif statuses.last == :planned
                      0
                    end
        when 3
          current = 1 if statuses.first == :done && statuses.last == :planned
        end
        if current
          status = statuses[current]
          if [:failed, :running].include?(status) && chunks[current].length == 1
            return status
          end
        end
        :invalid
      end
    end
    extend ClassMethods
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action-plan-0.1.0 lib/action/state/class_methods.rb