Sha256: 20b2e8919762f2c9a2d76de603fd9341fb6221d93e2334106a7feda07c28b196

Contents?: true

Size: 1.74 KB

Versions: 179

Compression:

Stored size: 1.74 KB

Contents

require 'travis/client'

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

      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?
        not 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, "unknown state %p for %p" % [state, self] unless STATES.include? state
        end
    end
  end
end

Version data entries

179 entries across 179 versions & 3 rubygems

Version Path
travis-1.11.1 lib/travis/client/states.rb
travis-1.11.0 lib/travis/client/states.rb
travis-1.10.1.travis.1341.9 lib/travis/client/states.rb
travis-1.10.1.travis.1321.9 lib/travis/client/states.rb
travis-1.10.1.travis.1312.9 lib/travis/client/states.rb
travis-1.10.1.travis.1311.9 lib/travis/client/states.rb
travis-1.10.1.travis.1305.9 lib/travis/client/states.rb
travis-1.10.0 lib/travis/client/states.rb
travis-1.9.2.travis.1304.9 lib/travis/client/states.rb
travis-1.9.2.travis.1303.9 lib/travis/client/states.rb
travis-1.10.0.pre.rc4 lib/travis/client/states.rb
travis-1.10.0.pre.rc3 lib/travis/client/states.rb
travis-1.10.0.pre.rc2 lib/travis/client/states.rb
travis-1.9.2.travis.1288.9 lib/travis/client/states.rb
travis-1.9.2.travis.1285.9 lib/travis/client/states.rb
travis-1.9.2.travis.1279.9 lib/travis/client/states.rb
travis-1.10.0.pre.rc1 lib/travis/client/states.rb
travis-1.9.2.travis.1254.9 lib/travis/client/states.rb
travis-1.9.2.travis.1236.9 lib/travis/client/states.rb
travis-1.9.2.travis.1224.9 lib/travis/client/states.rb