Class: WSDL::Request::DSLContext
- Inherits:
- BasicObject
- Defined in:
- lib/wsdl/request/dsl_context.rb
Overview
Request DSL execution context. rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: SecurityDSLContext
Constant Summary collapse
- RESERVED_METHODS =
Reserved DSL method names that cannot be used as element names directly.
%i[tag header body ws_security text cdata comment pi xmlns attribute].freeze
Instance Attribute Summary collapse
- #document ⇒ Document readonly
- #security ⇒ WSDL::Security::Config readonly
Instance Method Summary collapse
-
#__document__ ⇒ Object
Internal document accessor used by Operation#prepare.
-
#__security__ ⇒ Object
Internal security accessor used by Operation#prepare.
-
#attribute(name, value) ⇒ Object
Adds an attribute to the current element.
-
#body ⇒ Object
SOAP Body section.
-
#cdata(content) ⇒ Object
Adds CDATA node to the current element.
-
#comment(text) ⇒ Object
Adds XML comment node to the current element.
-
#header ⇒ Object
SOAP Header section.
-
#initialize(document:, security:, limits:) ⇒ DSLContext
constructor
A new instance of DSLContext.
-
#method_missing(name, *_args) ⇒ Object
Explicitly reject unknown DSL methods.
-
#pi(target, content) ⇒ Object
Adds XML processing instruction node to the current element.
-
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
:nocov: Required by RuboCop but unreachable — BasicObject has no respond_to? to trigger this.
-
#tag(name, *args, **keyword_attrs, &block) ⇒ Object
Universal element creator.
-
#text(content) ⇒ Object
Adds text content node to the current element.
-
#ws_security(&block) ⇒ Object
WS-Security request configuration.
-
#xmlns(prefix, uri) ⇒ Object
Declares a namespace binding.
Constructor Details
#initialize(document:, security:, limits:) ⇒ DSLContext
Returns a new instance of DSLContext.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wsdl/request/dsl_context.rb', line 13 def initialize(document:, security:, limits:) @document = document @security = security @limits = limits @section = :body @in_section_block = false @stack = [] @element_count = 0 @attribute_count = 0 @namespaces = { 'wsse' => ::WSDL::Security::Constants::NS::Security::WSSE, 'wsu' => ::WSDL::Security::Constants::NS::Security::WSU, 'ds' => ::WSDL::Security::Constants::NS::Signature::DS, 'ec' => ::WSDL::Security::Constants::NS::Signature::EC, 'env' => ::WSDL::NS::SOAP_1_1, 'soap' => ::WSDL::NS::SOAP_1_1, 'soap12' => ::WSDL::NS::SOAP_1_2, 'xsi' => ::WSDL::NS::XSI } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_args) ⇒ Object
Explicitly reject unknown DSL methods.
142 143 144 145 146 147 |
# File 'lib/wsdl/request/dsl_context.rb', line 142 def method_missing(name, *_args, &) available = RESERVED_METHODS.map(&:inspect).join(', ') ::Kernel.raise ::WSDL::RequestDslError, "Unknown request DSL method #{name.inspect}. " \ "Use tag('#{name}') for elements, or one of the reserved methods: #{available}" end |
Instance Attribute Details
#document ⇒ Document (readonly)
36 37 38 |
# File 'lib/wsdl/request/dsl_context.rb', line 36 def document @document end |
#security ⇒ WSDL::Security::Config (readonly)
39 40 41 |
# File 'lib/wsdl/request/dsl_context.rb', line 39 def security @security end |
Instance Method Details
#__document__ ⇒ Object
Internal document accessor used by Operation#prepare.
132 133 134 |
# File 'lib/wsdl/request/dsl_context.rb', line 132 def __document__ @document end |
#__security__ ⇒ Object
Internal security accessor used by Operation#prepare.
137 138 139 |
# File 'lib/wsdl/request/dsl_context.rb', line 137 def __security__ @security end |
#attribute(name, value) ⇒ Object
Adds an attribute to the current element.
127 128 129 |
# File 'lib/wsdl/request/dsl_context.rb', line 127 def attribute(name, value) add_attribute(current_node!, name, value) end |
#body ⇒ Object
SOAP Body section.
84 85 86 |
# File 'lib/wsdl/request/dsl_context.rb', line 84 def body(&) with_section(:body, &) end |
#cdata(content) ⇒ Object
Adds CDATA node to the current element.
102 103 104 |
# File 'lib/wsdl/request/dsl_context.rb', line 102 def cdata(content) current_node!.children << ::WSDL::Request::CDataNode.new(content.to_s) end |
#comment(text) ⇒ Object
Adds XML comment node to the current element.
107 108 109 |
# File 'lib/wsdl/request/dsl_context.rb', line 107 def comment(text) current_node!.children << ::WSDL::Request::Comment.new(text.to_s) end |
#header ⇒ Object
SOAP Header section.
79 80 81 |
# File 'lib/wsdl/request/dsl_context.rb', line 79 def header(&) with_section(:header, &) end |
#pi(target, content) ⇒ Object
Adds XML processing instruction node to the current element.
112 113 114 115 |
# File 'lib/wsdl/request/dsl_context.rb', line 112 def pi(target, content) ::WSDL::Request::Names.validate_ncname!(target, kind: 'processing instruction target') current_node!.children << ::WSDL::Request::ProcessingInstruction.new(target.to_s, content.to_s) end |
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
:nocov: Required by RuboCop but unreachable — BasicObject has no respond_to? to trigger this.
151 152 153 |
# File 'lib/wsdl/request/dsl_context.rb', line 151 def respond_to_missing?(_name, _include_private = false) false end |
#tag(name, *args, **keyword_attrs, &block) ⇒ Object
Universal element creator. rubocop:disable Metrics/AbcSize
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wsdl/request/dsl_context.rb', line 43 def tag(name, *args, **keyword_attrs, &block) validate_depth!(@stack.length + 1) validate_element_count!(@element_count + 1) qname = name.to_s ::WSDL::Request::Names.validate_qname!(qname) prefix, local_name = ::WSDL::Request::Names.parse_qname(qname) namespace_uri = lookup_namespace(prefix) if prefix && namespace_uri.nil? ::Kernel.raise ::WSDL::RequestDslError, "Undeclared namespace prefix #{prefix.inspect} for #{qname.inspect}" end text_content, hash_attrs = parse_tag_args(args, keyword_attrs) node = ::WSDL::Request::Node.new(name: qname, prefix:, local_name:, namespace_uri:) hash_attrs.each do |attr_name, value| add_attribute(node, attr_name, value) end append_node(node) @element_count += 1 node.children << ::WSDL::Request::TextNode.new(text_content.to_s) if text_content if block @stack << node instance_exec(&block) @stack.pop end node end |
#text(content) ⇒ Object
Adds text content node to the current element.
97 98 99 |
# File 'lib/wsdl/request/dsl_context.rb', line 97 def text(content) current_node!.children << ::WSDL::Request::TextNode.new(content.to_s) end |
#ws_security(&block) ⇒ Object
WS-Security request configuration.
89 90 91 92 93 94 |
# File 'lib/wsdl/request/dsl_context.rb', line 89 def ws_security(&block) ::Kernel.raise ::WSDL::RequestDslError, 'ws_security requires a block' unless block context = SecurityDSLContext.new(@security) context.instance_exec(&block) end |
#xmlns(prefix, uri) ⇒ Object
Declares a namespace binding.
118 119 120 121 122 123 124 |
# File 'lib/wsdl/request/dsl_context.rb', line 118 def xmlns(prefix, uri) normalized_prefix = normalize_and_validate_prefix!(prefix) namespace_decl = ::WSDL::Request::NamespaceDecl.new(normalized_prefix, uri.to_s) @namespaces[normalized_prefix || ''] = uri.to_s @document.namespace_decls << namespace_decl @stack.last&.namespace_decls&.<<(namespace_decl) end |