Class: WSDL::Schema::Collection
- Inherits:
-
Object
- Object
- WSDL::Schema::Collection
- Includes:
- Enumerable
- Defined in:
- lib/wsdl/schema/collection.rb
Overview
A collection of XML Schema definitions with lookup capabilities.
Aggregates multiple Definition instances and provides unified lookup methods for finding schema components (elements, types, attributes) by namespace and local name.
Constant Summary collapse
- EMPTY_DEFINITIONS =
Shared empty array returned for unknown namespaces to avoid allocation.
[].freeze
Lookups collapse
-
#find_attribute(namespace, name) ⇒ Node?
Finds a global attribute by namespace and name.
-
#find_attribute_group(namespace, name) ⇒ Node?
Finds an attribute group by namespace and name.
-
#find_by_namespace(namespace) ⇒ Definition?
Finds the first definition matching a target namespace.
-
#find_complex_type(namespace, name) ⇒ Node?
Finds a complex type by namespace and name.
-
#find_element(namespace, name) ⇒ Node?
Finds a global element by namespace and name.
-
#find_group(namespace, name) ⇒ Node?
Finds a model group by namespace and name.
-
#find_simple_type(namespace, name) ⇒ Node?
Finds a simple type by namespace and name.
-
#find_type(namespace, name) ⇒ Node?
Finds a type (complex or simple) by namespace and name.
Instance Method Summary collapse
-
#<<(definition) ⇒ Collection
Adds a definition to the collection.
-
#each {|definition| ... } ⇒ Enumerator, Collection
Iterates over each definition in the collection.
-
#initialize ⇒ Collection
constructor
Creates a new empty collection.
-
#push(definitions) ⇒ Collection
Adds multiple definitions to the collection.
-
#release_dom_references! ⇒ void
Releases all references to the Nokogiri DOM from every definition in the collection.
Constructor Details
#initialize ⇒ Collection
Creates a new empty collection.
25 26 27 28 |
# File 'lib/wsdl/schema/collection.rb', line 25 def initialize @definitions = [] @by_namespace = {} end |
Instance Method Details
#<<(definition) ⇒ Collection
Adds a definition to the collection.
34 35 36 37 38 |
# File 'lib/wsdl/schema/collection.rb', line 34 def <<(definition) @definitions << definition (@by_namespace[definition.target_namespace] ||= []) << definition self end |
#each {|definition| ... } ⇒ Enumerator, Collection
Iterates over each definition in the collection.
57 58 59 |
# File 'lib/wsdl/schema/collection.rb', line 57 def each(&) @definitions.each(&) end |
#find_attribute(namespace, name) ⇒ Node?
Finds a global attribute by namespace and name.
Searches all definitions sharing the namespace per XSD §4.2.3.
143 144 145 146 147 148 149 |
# File 'lib/wsdl/schema/collection.rb', line 143 def find_attribute(namespace, name) definitions_for_namespace(namespace).each do |definition| attribute = definition.attributes[name] return attribute if attribute end nil end |
#find_attribute_group(namespace, name) ⇒ Node?
Finds an attribute group by namespace and name.
Searches all definitions sharing the namespace per XSD §4.2.3.
173 174 175 176 177 178 179 |
# File 'lib/wsdl/schema/collection.rb', line 173 def find_attribute_group(namespace, name) definitions_for_namespace(namespace).each do |definition| group = definition.attribute_groups[name] return group if group end nil end |
#find_by_namespace(namespace) ⇒ Definition?
Finds the first definition matching a target namespace.
185 186 187 |
# File 'lib/wsdl/schema/collection.rb', line 185 def find_by_namespace(namespace) definitions_for_namespace(namespace).first end |
#find_complex_type(namespace, name) ⇒ Node?
Finds a complex type by namespace and name.
Searches all definitions sharing the namespace per XSD §4.2.3.
96 97 98 99 100 101 102 |
# File 'lib/wsdl/schema/collection.rb', line 96 def find_complex_type(namespace, name) definitions_for_namespace(namespace).each do |definition| type = definition.complex_types[name] return type if type end nil end |
#find_element(namespace, name) ⇒ Node?
Finds a global element by namespace and name.
Searches all definitions sharing the namespace per XSD §4.2.3.
81 82 83 84 85 86 87 |
# File 'lib/wsdl/schema/collection.rb', line 81 def find_element(namespace, name) definitions_for_namespace(namespace).each do |definition| element = definition.elements[name] return element if element end nil end |
#find_group(namespace, name) ⇒ Node?
Finds a model group by namespace and name.
Searches all definitions sharing the namespace per XSD §4.2.3.
158 159 160 161 162 163 164 |
# File 'lib/wsdl/schema/collection.rb', line 158 def find_group(namespace, name) definitions_for_namespace(namespace).each do |definition| group = definition.groups[name] return group if group end nil end |
#find_simple_type(namespace, name) ⇒ Node?
Finds a simple type by namespace and name.
Searches all definitions sharing the namespace per XSD §4.2.3.
111 112 113 114 115 116 117 |
# File 'lib/wsdl/schema/collection.rb', line 111 def find_simple_type(namespace, name) definitions_for_namespace(namespace).each do |definition| type = definition.simple_types[name] return type if type end nil end |
#find_type(namespace, name) ⇒ Node?
Finds a type (complex or simple) by namespace and name.
Searches all definitions sharing the namespace per XSD §4.2.3. Complex and simple types share a symbol space within a namespace, so both are checked per definition before moving to the next.
128 129 130 131 132 133 134 |
# File 'lib/wsdl/schema/collection.rb', line 128 def find_type(namespace, name) definitions_for_namespace(namespace).each do |definition| type = definition.complex_types[name] || definition.simple_types[name] return type if type end nil end |
#push(definitions) ⇒ Collection
Adds multiple definitions to the collection.
44 45 46 47 48 49 50 |
# File 'lib/wsdl/schema/collection.rb', line 44 def push(definitions) @definitions.concat(definitions) definitions.each do |d| (@by_namespace[d.target_namespace] ||= []) << d end self end |
#release_dom_references! ⇒ void
This method returns an undefined value.
Releases all references to the Nokogiri DOM from every definition in the collection.
Called by Parser.parse after the Definition IR is built so the GC can reclaim the DOM trees while the collection is still reachable.
68 69 70 |
# File 'lib/wsdl/schema/collection.rb', line 68 def release_dom_references! @definitions.each(&:release_dom_references!) end |