Class: WSDL::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/wsdl/config.rb

Overview

Behavioral configuration for Client instances.

Groups all parse-time and request-time settings into a single frozen value object. Accepts the same keyword arguments as WSDL::Client#initialize for the behavioral subset (everything except the WSDL source, HTTP adapter, and cache).

Examples:

Create with defaults

config = WSDL::Config.new

Override specific settings

config = WSDL::Config.new(format_xml: false, strict_schema: false)

Derive a modified copy

relaxed = config.with(strict_schema: false)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format_xml: true, strict_schema: true, sandbox_paths: nil, limits: nil) ⇒ Config

Returns a new instance of Config.

Parameters:

  • format_xml (Boolean) (defaults to: true)

    whether to format XML output with indentation. Set to false for whitespace-sensitive SOAP servers. Defaults to true.

  • strict_schema (Boolean) (defaults to: true)

    strict schema handling and request validation mode.

    • true (default) enables strict schema imports and strict request validation
    • false enables best-effort schema imports and relaxed request validation
  • sandbox_paths (Array<String>, nil) (defaults to: nil)

    directories where file access is allowed. When nil (default), sandbox is determined automatically based on WSDL source:

    • URL source -> file access disabled (all imports must use URLs)
    • File source -> sandboxed to the WSDL's parent directory When provided, overrides the automatic sandbox with the specified directories.
  • limits (Limits, nil) (defaults to: nil)

    resource limits for DoS protection. If nil, uses WSDL.limits. Use a custom Limits instance to increase limits for specific WSDLs that exceed defaults.



35
36
37
38
39
40
41
42
43
# File 'lib/wsdl/config.rb', line 35

def initialize(format_xml: true, strict_schema: true,
               sandbox_paths: nil, limits: nil)
  @format_xml = format_xml
  @strict_schema = strict_schema ? true : false
  @sandbox_paths = sandbox_paths
  @limits = limits || WSDL.limits

  freeze
end

Instance Attribute Details

#format_xmlBoolean (readonly)

Returns whether to format XML output with indentation.

Returns:

  • (Boolean)

    whether to format XML output with indentation



46
47
48
# File 'lib/wsdl/config.rb', line 46

def format_xml
  @format_xml
end

#limitsLimits (readonly)

Returns resource limits for DoS protection.

Returns:

  • (Limits)

    resource limits for DoS protection



55
56
57
# File 'lib/wsdl/config.rb', line 55

def limits
  @limits
end

#sandbox_pathsArray<String>? (readonly)

Returns allowed directories for file access.

Returns:

  • (Array<String>, nil)

    allowed directories for file access



52
53
54
# File 'lib/wsdl/config.rb', line 52

def sandbox_paths
  @sandbox_paths
end

#strict_schemaBoolean (readonly)

Returns strict schema handling and request validation mode.

Returns:

  • (Boolean)

    strict schema handling and request validation mode



49
50
51
# File 'lib/wsdl/config.rb', line 49

def strict_schema
  @strict_schema
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns true if equal.

Parameters:

  • other (Object)

    the object to compare

Returns:

  • (Boolean)

    true if equal



90
91
92
93
94
# File 'lib/wsdl/config.rb', line 90

def ==(other)
  return false unless other.is_a?(Config)

  to_h == other.to_h
end

#hashInteger

Returns the hash code.

Returns:

  • (Integer)

    the hash code



99
100
101
# File 'lib/wsdl/config.rb', line 99

def hash
  to_h.hash
end

#inspectString

Returns human-readable representation.

Returns:

  • (String)

    human-readable representation



104
105
106
107
# File 'lib/wsdl/config.rb', line 104

def inspect
  parts = to_h.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
  "#<#{self.class.name} #{parts}>"
end

#to_hHash{Symbol => Object}

Returns the config as a hash.

Returns:

  • (Hash{Symbol => Object})

    the config as a hash



79
80
81
82
83
84
85
86
# File 'lib/wsdl/config.rb', line 79

def to_h
  {
    format_xml: @format_xml,
    strict_schema: @strict_schema,
    sandbox_paths: @sandbox_paths,
    limits: @limits
  }
end

#with(**options) ⇒ Config

Creates a new Config with some values changed.

Examples:

relaxed = config.with(strict_schema: false)

Parameters:

  • options (Hash)

    the settings to override

Options Hash (**options):

  • :format_xml (Boolean)
  • :strict_schema (Boolean)
  • :sandbox_paths (Array<String>, nil)
  • :limits (Limits, nil)

Returns:

  • (Config)

    a new Config instance with the specified changes



69
70
71
72
73
74
75
76
# File 'lib/wsdl/config.rb', line 69

def with(**options)
  self.class.new(
    format_xml: options.fetch(:format_xml, @format_xml),
    strict_schema: options.fetch(:strict_schema, @strict_schema),
    sandbox_paths: options.fetch(:sandbox_paths, @sandbox_paths),
    limits: options.fetch(:limits, @limits)
  )
end