Class: WSDL::Response::Builder
- Inherits:
-
Object
- Object
- WSDL::Response::Builder
- Defined in:
- lib/wsdl/response/builder.rb
Overview
Builds SOAP response XML from a Ruby hash using WSDL schema elements.
This is the inverse of Parser: where the parser converts SOAP XML into Ruby hashes, the builder converts Ruby hashes back into SOAP XML. The hash structure follows the same convention as Contract::Template#to_h, with type placeholders replaced by actual values.
The builder validates the hash against the schema during construction, catching unknown elements, missing required elements, type mismatches, and cardinality violations.
Constant Summary collapse
- TYPE_MAP =
Maps XSD type groups to accepted Ruby classes for validation.
{ string: [String], integer: [Integer], decimal: [Integer, Float, BigDecimal], float: [Integer, Float], boolean: [TrueClass, FalseClass], date: [Date, String], datetime: [Time, String], time: [Time, String], base64: [String], hex_binary: [String], list: [Array] }.freeze
Instance Method Summary collapse
-
#initialize(schema_elements:, soap_version: '1.1', output_style: 'document/literal', operation_name: nil, output_namespace: nil) ⇒ Builder
constructor
Creates a new builder for the given output schema.
-
#to_xml(hash) ⇒ String
Validates and serializes a Ruby hash into a SOAP envelope XML string.
-
#validate!(hash) ⇒ void
Validates a Ruby hash against the output schema without serializing.
Constructor Details
#initialize(schema_elements:, soap_version: '1.1', output_style: 'document/literal', operation_name: nil, output_namespace: nil) ⇒ Builder
Creates a new builder for the given output schema.
For RPC/literal operations, pass output_style, operation_name, and
output_namespace so the builder wraps message parts in the standard
operationNameResponse element per SOAP 1.1 §7.1.
67 68 69 70 71 72 73 74 75 |
# File 'lib/wsdl/response/builder.rb', line 67 def initialize(schema_elements:, soap_version: '1.1', output_style: 'document/literal', operation_name: nil, output_namespace: nil) @schema_elements = schema_elements @soap_version = soap_version @output_style = output_style @operation_name = operation_name @output_namespace = output_namespace end |
Instance Method Details
#to_xml(hash) ⇒ String
Validates and serializes a Ruby hash into a SOAP envelope XML string.
The hash represents the content inside the wrapper element. For example,
if the schema defines getBankResponse as the wrapper, the hash should
contain the children of that element (e.g. { details: { ... } }).
86 87 88 89 |
# File 'lib/wsdl/response/builder.rb', line 86 def to_xml(hash) validate!(hash) serialize(hash) end |
#validate!(hash) ⇒ void
This method returns an undefined value.
Validates a Ruby hash against the output schema without serializing.
Useful for checking response definitions at load time.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/wsdl/response/builder.rb', line 98 def validate!(hash) wrapper = @schema_elements.first return if wrapper.nil? if wrapper.complex_type? validate_hash(hash, wrapper, path: wrapper.name) else validate_parts(hash, @schema_elements) end end |