Class: WSDL::XML::Element Private
- Inherits:
-
Object
- Object
- WSDL::XML::Element
- Defined in:
- lib/wsdl/xml/element.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.
Represents an XML element definition used for building SOAP messages.
Elements are the building blocks of SOAP message structures. They can be either simple types (with a base type like string or integer) or complex types (with child elements). Elements track their cardinality (singular vs. array), namespace qualification, and support detection of recursive type definitions.
Constant Summary collapse
- EMPTY_ATTRIBUTES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Canonical frozen empty array shared for elements without attributes.
[].freeze
Instance Attribute Summary collapse
-
#any_content ⇒ Boolean
(also: #any_content?)
Whether this element allows arbitrary content via xs:any wildcard.
-
#attributes ⇒ Array<Attribute>
private
The XML attributes defined on this element.
-
#base_type ⇒ String?
The base type name for simple type elements (e.g., 'xsd:string').
-
#children ⇒ Array<Element>
The child elements for complex type elements.
-
#complex_type_id ⇒ String?
The complex type ID for tracking recursive type definitions.
-
#form ⇒ String
The element form ('qualified' or 'unqualified').
-
#max_occurs ⇒ String
Maximum occurrences for this element in schema terms.
-
#min_occurs ⇒ String
Minimum occurrences for this element in schema terms.
-
#name ⇒ String
The local name of this element.
-
#namespace ⇒ String?
The namespace URI for this element.
-
#nillable ⇒ Boolean
(also: #nillable?)
Whether this element can have a nil value (xsi:nil="true").
-
#parent ⇒ Element?
The parent element in the element tree.
-
#recursive_type ⇒ String?
The name of the recursive type definition, if any.
-
#singular ⇒ Boolean
(also: #singular?)
Whether this element appears at most once (singular) or can repeat (array).
Instance Method Summary collapse
-
#complex_type? ⇒ Boolean
private
Returns whether this element is a complex type.
-
#freeze ⇒ self
private
Deep-freezes this element by also freezing the mutable +@children+ array.
-
#initialize ⇒ Element
constructor
private
Creates a new Element with default values.
-
#optional? ⇒ Boolean
private
True if the element is optional (minOccurs=0).
-
#recursive? ⇒ Boolean
private
Returns whether this element's type is defined recursively.
-
#required? ⇒ Boolean
private
True if the element is required (minOccurs>0).
-
#simple_type? ⇒ Boolean
private
Returns whether this element is a simple type.
-
#to_a(memo = [], stack = []) ⇒ Array<Array>
private
Converts this element and its children to an Array representation for inspection.
Constructor Details
#initialize ⇒ Element
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.
Creates a new Element with default values.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wsdl/xml/element.rb', line 29 def initialize @children = [] @attributes = EMPTY_ATTRIBUTES @recursive = false @singular = true @min_occurs = '1' @max_occurs = '1' @any_content = false @nillable = false end |
Instance Attribute Details
#any_content ⇒ Boolean Also known as: any_content?
Whether this element allows arbitrary content via xs:any wildcard. When true, the element can contain any well-formed XML elements beyond those explicitly defined in the schema.
151 152 153 |
# File 'lib/wsdl/xml/element.rb', line 151 def any_content @any_content end |
#attributes ⇒ Array<Attribute>
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.
The XML attributes defined on this element.
157 158 159 |
# File 'lib/wsdl/xml/element.rb', line 157 def attributes @attributes end |
#base_type ⇒ String?
The base type name for simple type elements (e.g., 'xsd:string').
83 84 85 |
# File 'lib/wsdl/xml/element.rb', line 83 def base_type @base_type end |
#children ⇒ Array<Element>
The child elements for complex type elements.
144 145 146 |
# File 'lib/wsdl/xml/element.rb', line 144 def children @children end |
#complex_type_id ⇒ String?
The complex type ID for tracking recursive type definitions. Format is "namespace:localName".
139 140 141 |
# File 'lib/wsdl/xml/element.rb', line 139 def complex_type_id @complex_type_id end |
#form ⇒ String
The element form ('qualified' or 'unqualified'). Qualified elements include namespace prefixes in the XML output.
59 60 61 |
# File 'lib/wsdl/xml/element.rb', line 59 def form @form end |
#max_occurs ⇒ String
Maximum occurrences for this element in schema terms.
99 100 101 |
# File 'lib/wsdl/xml/element.rb', line 99 def max_occurs @max_occurs end |
#min_occurs ⇒ String
Minimum occurrences for this element in schema terms.
94 95 96 |
# File 'lib/wsdl/xml/element.rb', line 94 def min_occurs @min_occurs end |
#name ⇒ String
The local name of this element.
48 49 50 |
# File 'lib/wsdl/xml/element.rb', line 48 def name @name end |
#namespace ⇒ String?
The namespace URI for this element.
53 54 55 |
# File 'lib/wsdl/xml/element.rb', line 53 def namespace @namespace end |
#nillable ⇒ Boolean Also known as: nillable?
Whether this element can have a nil value (xsi:nil="true"). This corresponds to the nillable="true" attribute in the XSD schema.
115 116 117 |
# File 'lib/wsdl/xml/element.rb', line 115 def nillable @nillable end |
#parent ⇒ Element?
The parent element in the element tree.
43 44 45 |
# File 'lib/wsdl/xml/element.rb', line 43 def parent @parent end |
#recursive_type ⇒ String?
The name of the recursive type definition, if any.
132 133 134 |
# File 'lib/wsdl/xml/element.rb', line 132 def recursive_type @recursive_type end |
#singular ⇒ Boolean Also known as: singular?
Whether this element appears at most once (singular) or can repeat (array).
88 89 90 |
# File 'lib/wsdl/xml/element.rb', line 88 def singular @singular end |
Instance Method Details
#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 whether this element is a complex type.
Complex types contain child elements rather than simple text content.
76 77 78 |
# File 'lib/wsdl/xml/element.rb', line 76 def complex_type? !simple_type? end |
#freeze ⇒ self
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.
Deep-freezes this element by also freezing the mutable +@children+ array.
The +@attributes+ array is already frozen by the custom setter, so only +@children+ needs explicit freezing here.
180 181 182 183 |
# File 'lib/wsdl/xml/element.rb', line 180 def freeze @children.freeze super 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).
102 103 104 |
# File 'lib/wsdl/xml/element.rb', line 102 def optional? min_occurs.to_s == '0' 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 whether this element's type is defined recursively.
A recursive type definition means one of this element's ancestors has the same complex type as this element, which would cause infinite recursion if fully expanded.
125 126 127 |
# File 'lib/wsdl/xml/element.rb', line 125 def recursive? !!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).
107 108 109 |
# File 'lib/wsdl/xml/element.rb', line 107 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 whether this element is a simple type.
Simple types have a base type and contain only text content, not child elements.
67 68 69 |
# File 'lib/wsdl/xml/element.rb', line 67 def simple_type? !!base_type 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 for inspection.
Each element is represented as a tuple of [path, data], where path is an array of element names from the root, and data is a hash containing the element's properties.
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity -- straightforward tree traversal, splitting would hurt readability
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/wsdl/xml/element.rb', line 203 def to_a(memo = [], stack = []) new_stack = stack + [name] data = { namespace: namespace, form: form, singular: singular?, min_occurs: min_occurs, max_occurs: max_occurs } unless attributes.empty? data[:attributes] = attributes.to_h { |attribute| [attribute.name, { optional: attribute.optional? }] } end if recursive? data[:recursive_type] = recursive_type memo << [new_stack, data] elsif simple_type? data[:type] = base_type memo << [new_stack, data] elsif complex_type? data[:any_content] = true if any_content? memo << [new_stack, data] children.each do |child| child.to_a(memo, new_stack) end end memo end |