Class: WSDL::Contract::Template
- Inherits:
-
Object
- Object
- WSDL::Contract::Template
- Defined in:
- lib/wsdl/contract/template.rb
Overview
Request template scaffold for request/header/body part contracts.
Constant Summary collapse
- MODES =
Supported template rendering modes.
:minimalincludes only required elements/attributes:fullincludes all known elements/attributes
%i[minimal full].freeze
Instance Method Summary collapse
-
#initialize(section:, elements:, mode:) ⇒ Template
constructor
A new instance of Template.
-
#to_dsl ⇒ String
Returns a copy-pastable request DSL scaffold.
-
#to_h ⇒ Hash{Symbol => Object}
Returns inspection-oriented structure of the selected part.
Constructor Details
#initialize(section:, elements:, mode:) ⇒ Template
Returns a new instance of Template.
18 19 20 21 22 23 24 |
# File 'lib/wsdl/contract/template.rb', line 18 def initialize(section:, elements:, mode:) validate_mode!(mode) @section = section @elements = elements @mode = mode end |
Instance Method Details
#to_dsl ⇒ String
Returns a copy-pastable request DSL scaffold.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wsdl/contract/template.rb', line 40 def to_dsl lines = ['operation.prepare do'] if @section == :header lines << ' header do' append_element_lines(@elements, lines, 4) lines << ' end' else # Body content defaults to body section, no explicit wrapper needed append_element_lines(@elements, lines, 2) end lines << 'end' lines.join("\n") end |
#to_h ⇒ Hash{Symbol => Object}
Returns inspection-oriented structure of the selected part.
29 30 31 32 33 34 35 |
# File 'lib/wsdl/contract/template.rb', line 29 def to_h @elements.each_with_object({}) do |element, memo| next unless include_element?(element) memo[element.name.to_sym] = template_value_for(element) end end |