Class: WSDL::Schema::Collection

Inherits:
Object
  • Object
show all
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.

Examples:

collection = Schema::Collection.new
collection << Schema::Definition.new(schema_node, collection)
collection.find_element('http://example.com', 'User')

Lookups collapse

Instance Method Summary collapse

Constructor Details

#initializeCollection

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.

Parameters:

  • definition (Definition)

    the schema definition to add

Returns:



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.

Yields:

  • (definition)

    yields each definition

Yield Parameters:

Returns:

  • (Enumerator, Collection)

    enumerator if no block given



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the attribute

  • context (String, nil) (defaults to: nil)

    additional context for error messages

Returns:

  • (Node)

    the attribute node

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the attribute group

  • context (String, nil) (defaults to: nil)

    additional context for error messages

Returns:

  • (Node)

    the attribute group node

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

  • context (String, nil) (defaults to: nil)

    additional context for error messages

Returns:

  • (Node)

    the complex type node

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the element

  • context (String, nil) (defaults to: nil)

    additional context for error messages

Returns:

  • (Node)

    the element node

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

  • context (String, nil) (defaults to: nil)

    additional context for error messages

Returns:

  • (Node)

    the simple type node

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

  • context (String, nil) (defaults to: nil)

    additional context for error messages

Returns:

  • (Node)

    the type node

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the attribute

Returns:

  • (Node, nil)

    the attribute node, or nil if not found

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the attribute group

Returns:

  • (Node, nil)

    the attribute group node, or nil if not found

Raises:



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.

Parameters:

  • namespace (String, nil)

    the target namespace URI

Returns:

  • (Definition, nil)

    the matching definition, or nil if not found



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

Returns:

  • (Node, nil)

    the complex type node, or nil if not found

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the element

Returns:

  • (Node, nil)

    the element node, or nil if not found

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

Returns:

  • (Node, nil)

    the simple type node, or nil if not found

Raises:



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.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

Returns:

  • (Node, nil)

    the type node, or nil if not found

Raises:



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.

Parameters:

  • definitions (Array<Definition>)

    the definitions to add

Returns:



37
38
39
40
# File 'lib/wsdl/schema/collection.rb', line 37

def push(definitions)
  @definitions.concat(definitions)
  self
end