Class: WSDL::Definition::ElementHash Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wsdl/definition/element_hash.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Frozen wrapper around a plain element hash that duck-types as XML::Element.

This allows consumers like Response::Parser, Response::Builder, and Request::Validator to work with Definition element data without modification — they call the same methods they would on XML::Element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ElementHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ElementHash.

Parameters:



15
16
17
18
19
20
# File 'lib/wsdl/definition/element_hash.rb', line 15

def initialize(data)
  @data = data
  @children = data[:children].map { |c| self.class.new(c) }.freeze
  @attributes = data[:attributes].map { |a| AttributeHash.new(a) }.freeze
  freeze
end

Instance Attribute Details

#attributesArray<AttributeHash> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns attribute definitions.

Returns:



111
112
113
# File 'lib/wsdl/definition/element_hash.rb', line 111

def attributes
  @attributes
end

#childrenArray<ElementHash> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns child elements.

Returns:



108
109
110
# File 'lib/wsdl/definition/element_hash.rb', line 108

def children
  @children
end

Instance Method Details

#any_content?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if this element allows xs:any wildcard content.

Returns:

  • (Boolean)

    true if this element allows xs:any wildcard content



73
74
75
# File 'lib/wsdl/definition/element_hash.rb', line 73

def any_content?
  @data[:any_content]
end

#base_typeString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns base type name (e.g. 'xsd:string').

Returns:

  • (String, nil)

    base type name (e.g. 'xsd:string')



43
44
45
# File 'lib/wsdl/definition/element_hash.rb', line 43

def base_type
  @data[:xsd_type]
end

#complex_type?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if this is a complex or recursive type element.

Returns:

  • (Boolean)

    true if this is a complex or recursive type element



53
54
55
# File 'lib/wsdl/definition/element_hash.rb', line 53

def complex_type?
  %w[complex recursive].include?(@data[:type])
end

#formString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns element form ('qualified' or 'unqualified').

Returns:

  • (String)

    element form ('qualified' or 'unqualified')



33
34
35
# File 'lib/wsdl/definition/element_hash.rb', line 33

def form
  @data[:form]
end

#kindSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns element kind (:simple, :complex, or :recursive).

Returns:

  • (Symbol)

    element kind (:simple, :complex, or :recursive)



38
39
40
# File 'lib/wsdl/definition/element_hash.rb', line 38

def kind
  @data[:type].to_sym
end

#list?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if this is an xs:list type.

Returns:

  • (Boolean)

    true if this is an xs:list type



63
64
65
# File 'lib/wsdl/definition/element_hash.rb', line 63

def list?
  @data[:list]
end

#max_occursString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns maxOccurs as a string ('unbounded' for infinity).

Returns:

  • (String)

    maxOccurs as a string ('unbounded' for infinity)



93
94
95
# File 'lib/wsdl/definition/element_hash.rb', line 93

def max_occurs
  @data[:max_occurs] == Float::INFINITY ? 'unbounded' : @data[:max_occurs].to_s
end

#min_occursString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns minOccurs as a string (for Validator compatibility).

Returns:

  • (String)

    minOccurs as a string (for Validator compatibility)



88
89
90
# File 'lib/wsdl/definition/element_hash.rb', line 88

def min_occurs
  @data[:min_occurs].to_s
end

#nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns local element name.

Returns:

  • (String)

    local element name



23
24
25
# File 'lib/wsdl/definition/element_hash.rb', line 23

def name
  @data[:name]
end

#namespaceString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns namespace URI.

Returns:

  • (String, nil)

    namespace URI



28
29
30
# File 'lib/wsdl/definition/element_hash.rb', line 28

def namespace
  @data[:namespace]
end

#nillable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if this element can be nil (xsi:nil="true").

Returns:

  • (Boolean)

    true if this element can be nil (xsi:nil="true")



68
69
70
# File 'lib/wsdl/definition/element_hash.rb', line 68

def nillable?
  @data[:nillable]
end

#optional?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if the element is optional (minOccurs=0).

Returns:

  • (Boolean)

    true if the element is optional (minOccurs=0)



98
99
100
# File 'lib/wsdl/definition/element_hash.rb', line 98

def optional?
  @data[:min_occurs].zero?
end

#recursive?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if this element has a recursive type definition.

Returns:

  • (Boolean)

    true if this element has a recursive type definition



78
79
80
# File 'lib/wsdl/definition/element_hash.rb', line 78

def recursive?
  @data[:type] == 'recursive'
end

#recursive_typeString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the recursive type name.

Returns:

  • (String, nil)

    the recursive type name



83
84
85
# File 'lib/wsdl/definition/element_hash.rb', line 83

def recursive_type
  @data[:recursive_type]
end

#required?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if the element is required (minOccurs>0).

Returns:

  • (Boolean)

    true if the element is required (minOccurs>0)



103
104
105
# File 'lib/wsdl/definition/element_hash.rb', line 103

def required?
  !optional?
end

#simple_type?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if this is a simple type element.

Returns:

  • (Boolean)

    true if this is a simple type element



48
49
50
# File 'lib/wsdl/definition/element_hash.rb', line 48

def simple_type?
  @data[:type] == 'simple'
end

#singular?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if this element appears at most once.

Returns:

  • (Boolean)

    true if this element appears at most once



58
59
60
# File 'lib/wsdl/definition/element_hash.rb', line 58

def singular?
  @data[:singular]
end

#to_a(memo = [], stack = []) ⇒ Array<Array>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts this element and its children to an Array representation.

Produces the same format as XML::Element#to_a for compatibility with Contract::PartContract#paths.

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity -- mirrors XML::Element#to_a

Parameters:

  • memo (Array) (defaults to: [])

    accumulator for recursive traversal

  • stack (Array<String>) (defaults to: [])

    current path of element names

Returns:

  • (Array<Array>)

    array of [path, data] tuples



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/wsdl/definition/element_hash.rb', line 127

def to_a(memo = [], stack = [])
  new_stack = stack + [name]
  data = {
    namespace:, form:, singular: singular?,
    min_occurs:, max_occurs:, kind:
  }
  data[:attributes] = attributes.map(&:to_h) unless attributes.empty?
  case @data[:type]
  when 'recursive' then data[:recursive_type] = recursive_type
  when 'simple'
    data[:type] = base_type
    data[:list] = list?
  when 'complex' then data[:any_content] = any_content?
  end
  memo << [new_stack, data]
  children.each { |child| child.to_a(memo, new_stack) } if @data[:type] == 'complex'
  memo
end

#to_hHash{Symbol => Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the underlying element data.

Returns:

  • (Hash{Symbol => Object})

    the underlying element data



114
115
116
# File 'lib/wsdl/definition/element_hash.rb', line 114

def to_h
  @data
end