Module: Cts::Mpx::Driver::Helpers

Defined in:
lib/cts/mpx/driver/helpers.rb

Overview

Collection of simple helpers for the development of the SDK

Class Method Summary collapse

Class Method Details

.raise_if_not_a(objects, type) ⇒ nil

used to raise an exception if the array of objects is not of the specified type.

Parameters:

  • objects (Object[])

    array of objects to itterate through

  • type (Class)

    class to check the object array against.

Returns:

  • (nil)

    nil

Raises:

  • (ArgumentError)

    if the argument is not of the specified type



20
21
22
23
# File 'lib/cts/mpx/driver/helpers.rb', line 20

def raise_if_not_a(objects, type)
  objects.each { |k| Exceptions.raise_unless_argument_error?(k, type) }
  nil
end

.raise_if_not_a_hash(objects) ⇒ nil

Raise an error if any object in the array is not of a type Hash

Parameters:

  • objects (Object[])

    array of objects to test if a valid hash

Returns:

  • (nil)

    nil

Raises:

  • (ArgumentError)

    if the argument is not a [Hash]



46
47
48
49
# File 'lib/cts/mpx/driver/helpers.rb', line 46

def raise_if_not_a_hash(objects)
  raise_if_not_a(objects, Hash)
  nil
end

.raise_if_not_an_array(objects) ⇒ nil

Raise an error if any object in the array is not of a type Array

Parameters:

  • objects (Object[])

    array of objects to test if a valid array

Returns:

  • (nil)

    nil

Raises:

  • (ArgumentError)

    if the argument is not an [Array]



33
34
35
36
# File 'lib/cts/mpx/driver/helpers.rb', line 33

def raise_if_not_an_array(objects)
  raise_if_not_a(objects, Array)
  nil
end

.required_arguments(keywords, a_binding) ⇒ nil

Raise an error if any keywords are not included inside of a specified binding.

Parameters:

  • keywords (Object)

    list of keywords to check.

  • a_binding (Binding)

    binding to check for local variables

Returns:

  • (nil)

    nil

Raises:

  • (ArgumentError)

    if the argument is not of the specified type.



60
61
62
63
# File 'lib/cts/mpx/driver/helpers.rb', line 60

def required_arguments(keywords, a_binding)
  keywords.each { |keyword| Exceptions.raise_unless_required_keyword?(a_binding, keyword) }
  nil
end