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.
Lookups collapse
-
#fetch_attribute(namespace, name, context: nil) ⇒ Node
Fetches a global attribute by namespace and name.
-
#fetch_attribute_group(namespace, name, context: nil) ⇒ Node
Fetches an attribute group by namespace and name.
-
#fetch_complex_type(namespace, name, context: nil) ⇒ Node
Fetches a complex type by namespace and name.
-
#fetch_element(namespace, name, context: nil) ⇒ Node
Fetches a global element by namespace and name.
-
#fetch_simple_type(namespace, name, context: nil) ⇒ Node
Fetches a simple type by namespace and name.
-
#fetch_type(namespace, name, context: nil) ⇒ Node
Fetches a type (complex or simple) by namespace and name.
-
#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 a definition by its 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_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.
Constructor Details
#initialize ⇒ Collection
Creates a new empty collection.
20 21 22 |
# File 'lib/wsdl/schema/collection.rb', line 20 def initialize @definitions = [] end |
Instance Method Details
#<<(definition) ⇒ Collection
Adds a definition to the collection.
28 29 30 31 |
# File 'lib/wsdl/schema/collection.rb', line 28 def <<(definition) @definitions << definition self end |
#each {|definition| ... } ⇒ Enumerator, Collection
Iterates over each definition in the collection.
47 48 49 |
# File 'lib/wsdl/schema/collection.rb', line 47 def each(&) @definitions.each(&) end |
#fetch_attribute(namespace, name, context: nil) ⇒ Node
Fetches a global attribute by namespace and name.
Unlike #find_attribute, this raises when the attribute itself is missing.
201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/wsdl/schema/collection.rb', line 201 def fetch_attribute(namespace, name, context: nil) definition = fetch_schema_definition!(:attribute, namespace, name, context:) attribute = definition.attributes[name] return attribute if attribute raise_missing_component!( component: :attribute, namespace:, name:, available_components: definition.attributes.keys, context: ) end |
#fetch_attribute_group(namespace, name, context: nil) ⇒ Node
Fetches an attribute group by namespace and name.
Unlike #find_attribute_group, this raises when the group itself is missing.
237 238 239 240 241 242 243 244 |
# File 'lib/wsdl/schema/collection.rb', line 237 def fetch_attribute_group(namespace, name, context: nil) definition = fetch_schema_definition!(:attribute_group, namespace, name, context:) group = definition.attribute_groups[name] return group if group raise_missing_component!(component: :attribute_group, namespace:, name:, available_components: definition.attribute_groups.keys, context:) end |
#fetch_complex_type(namespace, name, context: nil) ⇒ Node
Fetches a complex type by namespace and name.
Unlike #find_complex_type, this raises when the type itself is missing.
106 107 108 109 110 111 112 113 |
# File 'lib/wsdl/schema/collection.rb', line 106 def fetch_complex_type(namespace, name, context: nil) definition = fetch_schema_definition!(:complex_type, namespace, name, context:) type = definition.complex_types[name] return type if type raise_missing_component!(component: :complex_type, namespace:, name:, available_components: definition.complex_types.keys, context:) end |
#fetch_element(namespace, name, context: nil) ⇒ Node
Fetches a global element by namespace and name.
Unlike #find_element, this raises when the element itself is missing.
75 76 77 78 79 80 81 82 |
# File 'lib/wsdl/schema/collection.rb', line 75 def fetch_element(namespace, name, context: nil) definition = fetch_schema_definition!(:element, namespace, name, context:) element = definition.elements[name] return element if element raise_missing_component!(component: :element, namespace:, name:, available_components: definition.elements.keys, context:) end |
#fetch_simple_type(namespace, name, context: nil) ⇒ Node
Fetches a simple type by namespace and name.
Unlike #find_simple_type, this raises when the type itself is missing.
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/wsdl/schema/collection.rb', line 137 def fetch_simple_type(namespace, name, context: nil) definition = fetch_schema_definition!(:simple_type, namespace, name, context:) type = definition.simple_types[name] return type if type raise_missing_component!( component: :simple_type, namespace:, name:, available_components: definition.simple_types.keys, context: ) end |
#fetch_type(namespace, name, context: nil) ⇒ Node
Fetches a type (complex or simple) by namespace and name.
Unlike #find_type, this raises when the type itself is missing.
170 171 172 173 174 175 176 177 |
# File 'lib/wsdl/schema/collection.rb', line 170 def fetch_type(namespace, name, context: nil) definition = fetch_schema_definition!(:type, namespace, name, context:) type = definition.complex_types[name] || definition.simple_types[name] return type if type available = (definition.complex_types.keys + definition.simple_types.keys).uniq raise_missing_component!(component: :type, namespace:, name:, available_components: available, context:) end |
#find_attribute(namespace, name) ⇒ Node?
Finds a global attribute by namespace and name.
185 186 187 188 189 190 |
# File 'lib/wsdl/schema/collection.rb', line 185 def find_attribute(namespace, name) definition = find_by_namespace(namespace) raise_missing_schema_namespace!(component: :attribute, namespace:, name:) unless definition definition.attributes[name] end |
#find_attribute_group(namespace, name) ⇒ Node?
Finds an attribute group by namespace and name.
221 222 223 224 225 226 |
# File 'lib/wsdl/schema/collection.rb', line 221 def find_attribute_group(namespace, name) definition = find_by_namespace(namespace) raise_missing_schema_namespace!(component: :attribute_group, namespace:, name:) unless definition definition.attribute_groups[name] end |
#find_by_namespace(namespace) ⇒ Definition?
Finds a definition by its target namespace.
250 251 252 |
# File 'lib/wsdl/schema/collection.rb', line 250 def find_by_namespace(namespace) find { |definition| definition.target_namespace == namespace } end |
#find_complex_type(namespace, name) ⇒ Node?
Finds a complex type by namespace and name.
90 91 92 93 94 95 |
# File 'lib/wsdl/schema/collection.rb', line 90 def find_complex_type(namespace, name) definition = find_by_namespace(namespace) raise_missing_schema_namespace!(component: :complex_type, namespace:, name:) unless definition definition.complex_types[name] end |
#find_element(namespace, name) ⇒ Node?
Finds a global element by namespace and name.
59 60 61 62 63 64 |
# File 'lib/wsdl/schema/collection.rb', line 59 def find_element(namespace, name) definition = find_by_namespace(namespace) raise_missing_schema_namespace!(component: :element, namespace:, name:) unless definition definition.elements[name] end |
#find_simple_type(namespace, name) ⇒ Node?
Finds a simple type by namespace and name.
121 122 123 124 125 126 |
# File 'lib/wsdl/schema/collection.rb', line 121 def find_simple_type(namespace, name) definition = find_by_namespace(namespace) raise_missing_schema_namespace!(component: :simple_type, namespace:, name:) unless definition definition.simple_types[name] end |
#find_type(namespace, name) ⇒ Node?
Finds a type (complex or simple) by namespace and name.
157 158 159 |
# File 'lib/wsdl/schema/collection.rb', line 157 def find_type(namespace, name) find_complex_type(namespace, name) || find_simple_type(namespace, name) end |
#push(definitions) ⇒ Collection
Adds multiple definitions to the collection.
37 38 39 40 |
# File 'lib/wsdl/schema/collection.rb', line 37 def push(definitions) @definitions.concat(definitions) self end |