Module: Cts::Mpx::Aci::Validators
- Defined in:
- lib/cts/mpx/aci/validators.rb
Overview
Wireline Validators
Class Method Summary collapse
- .field_reference?(uri) ⇒ Boolean
-
.image_deployable?(image) ⇒ Boolean
test if a image will depoly.
-
.image_directory?(image_directory) ⇒ Boolean
test if a directory is an image_directory.
-
.info_file?(filename) ⇒ Boolean
Test if a string is a transformed_reference or not.
-
.reference?(uri) ⇒ Boolean
Test if a string is a reference or not.
-
.transformed_field_reference?(string) ⇒ Boolean
Test if a string is a transformed_field_reference or not.
-
.transformed_reference?(string) ⇒ Boolean
Test if a string is a transformed_reference or not.
Class Method Details
.field_reference?(uri) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cts/mpx/aci/validators.rb', line 15 def field_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 unless ref.path =~ /Field\/\d+/ return false if ref.path =~ /\/\D+$/ true end |
.image_deployable?(image) ⇒ Boolean
test if a image will depoly
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cts/mpx/aci/validators.rb', line 85 def image_deployable?(image) return false if image.state == :transformed || image.state == 'transformed' return false if image.entries.collection.empty? image.entries.each do |entry| Transformations.traverse_for(entry.to_h, :untransform) do |_k, v| return false if v =~ /^urn:cts:aci:no-(gu)?id-found$/ end end true end |
.image_directory?(image_directory) ⇒ Boolean
test if a directory is an image_directory
76 77 78 79 80 |
# File 'lib/cts/mpx/aci/validators.rb', line 76 def image_directory?(image_directory) return false unless File.exist? "#{image_directory}/info.json" true end |
.info_file?(filename) ⇒ Boolean
Test if a string is a transformed_reference or not
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/cts/mpx/aci/validators.rb', line 100 def info_file?(filename) raise "could not find an info.json" unless File.exist? filename begin Oj.load(File.read(filename)) rescue Oj::ParseError return false end true end |
.reference?(uri) ⇒ Boolean
Test if a string is a reference or not
11 12 13 |
# File 'lib/cts/mpx/aci/validators.rb', line 11 def reference?(uri) Cts::Mpx::Validators.reference?(uri) end |
.transformed_field_reference?(string) ⇒ Boolean
Test if a string is a transformed_field_reference or not
66 67 68 69 70 71 |
# File 'lib/cts/mpx/aci/validators.rb', line 66 def transformed_field_reference?(string) return false unless transformed_reference? string return false unless /Field:\d*:.*$/.match? string true end |
.transformed_reference?(string) ⇒ Boolean
Test if a string is a transformed_reference or not
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cts/mpx/aci/validators.rb', line 34 def transformed_reference?(string) return true if [ 'urn:cts:aci:target-account', 'urn:cts:aci:no-id-found', 'urn:cts:aci:no-guid-found', 'urn:cts:aci:no-custom-field-found' ].include? string urn_regex = /^(?i:urn:(?!urn:)([cC][tT][sS]):(?<nss>(?:[a-z0-9()\/+,-.:=@;$_!*']|%[0-9a-f]{2})+))$/ return false unless urn_regex =~ string nss = urn_regex.match(string)["nss"] segments = nss.split(":") return false unless /^([aA][cC][iI])$/ =~ segments[0] begin service = Services[URI.decode_www_form_component(segments[1])] rescue RuntimeError return false end return false unless service.endpoints.include? segments[2].gsub('Field', '/Field') return false unless /\A\d+\z/ =~ segments[3] true end |