Sha256: e12a0e4f10e52d8b1df09ecfef3b840fc3fad8fbdf7f1becdea6f5f488add275

Contents?: true

Size: 1.77 KB

Versions: 6

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require 'travis/client'

module Travis
  module Client
    module States
      STATES = %w[created queued received started passed failed errored canceled ready].freeze

      def ready?
        state == 'ready'
      end

      def pending?
        check_state
        %w[created started queued received].include? state
      end

      def started?
        check_state
        state != 'created' and state != 'received' and state != 'queued'
      end

      def received?
        check_state
        state != 'created' and state != 'queued'
      end

      def queued?
        check_state
        state != 'created'
      end

      def finished?
        !pending?
      end

      def passed?
        check_state
        state == 'passed'
      end

      def errored?
        check_state
        state == 'errored'
      end

      def failed?
        check_state
        state == 'failed'
      end

      def canceled?
        check_state
        state == 'canceled'
      end

      def unsuccessful?
        errored? or failed? or canceled?
      end

      def created?
        check_state
        !!state
      end

      def color
        case state
        when 'created', 'queued', 'received', 'started' then 'yellow'
        when 'passed', 'ready'                then 'green'
        when 'errored', 'canceled', 'failed'  then 'red'
        end
      end

      def yellow?
        color == 'yellow'
      end

      def green?
        color == 'green'
      end

      def red?
        color == 'red'
      end

      def running?
        state == 'started'
      end

      alias successful? passed?

      private

      def check_state
        raise Error, format('unknown state %p for %p', state, self) unless STATES.include? state
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
travis-1.14.0 lib/travis/client/states.rb
travis-1.13.3 lib/travis/client/states.rb
travis-1.13.2 lib/travis/client/states.rb
travis-1.13.1 lib/travis/client/states.rb
travis-1.13.0 lib/travis/client/states.rb
travis-1.12.0 lib/travis/client/states.rb