Class: Mxup::WaitSpec

Inherits:
Struct
  • Object
show all
Defined in:
lib/mxup/config.rb

Overview

A readiness check attached to a window.

Constant Summary collapse

CHECK_TYPES =
%w[tcp http path script].freeze
OPTION_KEYS =
%w[timeout interval label].freeze
ALLOWED_KEYS =
(CHECK_TYPES + OPTION_KEYS).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#intervalObject

Returns the value of attribute interval

Returns:

  • (Object)

    the current value of interval



387
388
389
# File 'lib/mxup/config.rb', line 387

def interval
  @interval
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



387
388
389
# File 'lib/mxup/config.rb', line 387

def label
  @label
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



387
388
389
# File 'lib/mxup/config.rb', line 387

def target
  @target
end

#timeoutObject

Returns the value of attribute timeout

Returns:

  • (Object)

    the current value of timeout



387
388
389
# File 'lib/mxup/config.rb', line 387

def timeout
  @timeout
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



387
388
389
# File 'lib/mxup/config.rb', line 387

def type
  @type
end

Class Method Details

.parse(raw) ⇒ Object



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/mxup/config.rb', line 392

def self.parse(raw)
  case raw
  when nil
    nil
  when String
    new(type: :tcp, target: raw, timeout: nil, interval: 2, label: raw)
  when Hash
    extra = raw.keys.map(&:to_s) - ALLOWED_KEYS
    unless extra.empty?
      raise ArgumentError,
            "wait_for: unknown key(s) #{extra.map(&:inspect).join(', ')} " \
            "(allowed: #{ALLOWED_KEYS.join(', ')})"
    end
    found = CHECK_TYPES & raw.keys
    unless found.size == 1
      raise ArgumentError,
            "wait_for must specify exactly one of: #{CHECK_TYPES.join(', ')}"
    end
    type          = found.first
    target        = raw[type]
    default_label = type == 'script' ? 'readiness check' : target
    new(
      type:     type.to_sym,
      target:   target,
      timeout:  raw['timeout'],
      interval: raw['interval'] || 2,
      label:    raw['label'] || default_label
    )
  else
    raise ArgumentError, "wait_for must be a string or hash, got #{raw.class}"
  end
end