Module: Cts::Mpx::Validators

Defined in:
lib/cts/mpx/validators.rb

Overview

Collection of methods that will validate input based on specific tests.

Class Method Summary collapse

Class Method Details

.account_id?(account_id) ⇒ Boolean

Validates if a string is a long form id

Parameters:

  • account_id (String)

    long form id

Returns:

  • (Boolean)

    true if it is a long form id, false if it is not.



12
13
14
15
16
17
18
# File 'lib/cts/mpx/validators.rb', line 12

def ()
  return true if  == 'urn:theplatform:auth:root'
  return false unless reference? 
  return false unless .downcase.match?(/\/account\/\d+$/)

  true
end

.argument_error?(data, type = nil) { ... } ⇒ boolean

Note:

test

Test to check for validity of argument by type, can also accept a block.

Parameters:

  • data (Object)

    object to check

  • type (Class) (defaults to: nil)

    class type to accept

Yields:

  • Description of block

Yield Returns:

  • (boolean)

    true if the outcome is valid, false otherwise.

Returns:

  • (boolean)

    true if the outcome is valid, false otherwise.



27
28
29
30
31
32
# File 'lib/cts/mpx/validators.rb', line 27

def argument_error?(data, type = nil, &block)
  return block.yield if block
  return true unless type && data.is_a?(type)

  false
end

.reference?(uri) ⇒ Boolean

Validates if a string is a reference

Parameters:

  • uri (String)

    reference

Returns:

  • (Boolean)

    true if it is a reference, false if it is not.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cts/mpx/validators.rb', line 37

def reference?(uri)
  begin
    ref = URI.parse uri
  rescue URI::InvalidURIError
    return false
  end

  return false if ref.host == 'web.theplatform.com'
  return false unless ref.scheme == "http" || ref.scheme == "https"
  return false unless ref.host.end_with? ".theplatform.com"
  return false if ref.host.start_with? 'feed.media.theplatform'

  true
end