Module: WSDL::Request::Names

Defined in:
lib/wsdl/request/names.rb

Overview

XML name validation helpers used by the request DSL.

Constant Summary collapse

NCNAME_PATTERN =

XML NCName validation pattern.

Returns:

  • (Regexp)
/\A[_\p{L}][\p{L}\p{N}_.-]*\z/u
RESERVED_PREFIXES =

Prefixes predeclared by the DSL and protected from override.

Returns:

  • (Array<String>)
%w[wsse wsu ds ec env soap soap12 xsi].freeze

Class Method Summary collapse

Class Method Details

.parse_qname(value) ⇒ Object

Returns [prefix, local_name]. Prefix may be nil.



35
36
37
38
39
40
41
42
43
# File 'lib/wsdl/request/names.rb', line 35

def parse_qname(value)
  text = value.to_s
  if text.include?(':')
    prefix, local = text.split(':', 2)
    [prefix, local]
  else
    [nil, text]
  end
end

.valid_ncname?(value) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/wsdl/request/names.rb', line 19

def valid_ncname?(value)
  return false if value.nil?

  text = value.to_s
  return false if text.empty?

  text.match?(NCNAME_PATTERN)
end

.validate_ncname!(value, kind: 'name') ⇒ Object

Raises:



28
29
30
31
32
# File 'lib/wsdl/request/names.rb', line 28

def validate_ncname!(value, kind: 'name')
  return if valid_ncname?(value)

  raise RequestDslError, "Invalid XML #{kind} #{value.inspect}: expected NCName"
end

.validate_prefix_override!(prefix) ⇒ Object

Raises:



59
60
61
62
63
# File 'lib/wsdl/request/names.rb', line 59

def validate_prefix_override!(prefix)
  return unless RESERVED_PREFIXES.include?(prefix)

  raise RequestDslError, "Namespace prefix #{prefix.inspect} is reserved and cannot be overridden"
end

.validate_qname!(value) ⇒ void

This method returns an undefined value.

Validates that a value is either an NCName or QName.

Parameters:

  • value (#to_s)

Raises:



50
51
52
53
54
55
56
57
# File 'lib/wsdl/request/names.rb', line 50

def validate_qname!(value)
  prefix, local = parse_qname(value)

  validate_ncname!(local, kind: 'local name')
  return if prefix.nil?

  validate_ncname!(prefix, kind: 'prefix')
end