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
-
.account_id?(account_id) ⇒ Boolean
Validates if a string is a long form id.
-
.argument_error?(data, type = nil) { ... } ⇒ boolean
Test to check for validity of argument by type, can also accept a block.
-
.reference?(uri) ⇒ Boolean
Validates if a string is a reference.
Class Method Details
.account_id?(account_id) ⇒ Boolean
Validates if a string is a long form id
12 13 14 15 16 17 18 |
# File 'lib/cts/mpx/validators.rb', line 12 def account_id?(account_id) return true if account_id == 'urn:theplatform:auth:root' return false unless reference? account_id return false unless account_id.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.
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
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 |