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

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



210
211
212
# File 'lib/mxup/config.rb', line 210

def interval
  @interval
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



210
211
212
# File 'lib/mxup/config.rb', line 210

def label
  @label
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



210
211
212
# File 'lib/mxup/config.rb', line 210

def target
  @target
end

#timeoutObject

Returns the value of attribute timeout

Returns:

  • (Object)

    the current value of timeout



210
211
212
# File 'lib/mxup/config.rb', line 210

def timeout
  @timeout
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



210
211
212
# File 'lib/mxup/config.rb', line 210

def type
  @type
end

Class Method Details

.parse(raw) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/mxup/config.rb', line 213

def self.parse(raw)
  case raw
  when nil
    nil
  when String
    new(type: :tcp, target: raw, timeout: nil, interval: 2, label: raw)
  when Hash
    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