Class: WSDL::Strictness

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

Overview

Controls how strictly the library enforces WSDL/XSD correctness.

Each setting independently controls a validation concern. Defaults are strict (Strictness.on). Disable individual checks when working with imperfect WSDLs rather than turning everything off.

Examples:

Disable only schema import strictness

WSDL.parse(url, strictness: { schema_imports: false })

Disable all strictness

WSDL.parse(url, strictness: false)

Derive with one setting changed

WSDL::Strictness.new.with(schema_imports: false)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_imports: true, schema_references: true, operation_overloading: true, request_validation: true) ⇒ Strictness



30
31
32
33
34
35
36
37
# File 'lib/wsdl/strictness.rb', line 30

def initialize(schema_imports: true, schema_references: true,
               operation_overloading: true, request_validation: true)
  @schema_imports = schema_imports ? true : false
  @schema_references = schema_references ? true : false
  @operation_overloading = operation_overloading ? true : false
  @request_validation = request_validation ? true : false
  freeze
end

Instance Attribute Details

#operation_overloadingBoolean (readonly)



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

def operation_overloading
  @operation_overloading
end

#request_validationBoolean (readonly)



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

def request_validation
  @request_validation
end

#schema_importsBoolean (readonly)



40
41
42
# File 'lib/wsdl/strictness.rb', line 40

def schema_imports
  @schema_imports
end

#schema_referencesBoolean (readonly)



43
44
45
# File 'lib/wsdl/strictness.rb', line 43

def schema_references
  @schema_references
end

Class Method Details

.offStrictness

Returns a new Strictness with all checks disabled.



80
81
82
83
# File 'lib/wsdl/strictness.rb', line 80

def self.off
  new(schema_imports: false, schema_references: false,
    operation_overloading: false, request_validation: false)
end

.onStrictness

Returns a new Strictness with all checks enabled.



73
74
75
# File 'lib/wsdl/strictness.rb', line 73

def self.on
  new
end

.resolve(value) ⇒ Strictness?

Coerces a value into a Strictness instance.

Accepts a Strictness object (returned as-is), a Hash of settings (forwarded to new), true (on), false (off), or nil.

Raises:

  • (ArgumentError)

    if the value type is not recognized



59
60
61
62
63
64
65
66
67
68
# File 'lib/wsdl/strictness.rb', line 59

def self.resolve(value)
  case value
  when Strictness then value
  when Hash then new(**value)
  when true then on
  when false then off
  when nil then nil
  else raise ArgumentError, "Cannot coerce #{value.inspect} into a Strictness"
  end
end

Instance Method Details

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



109
110
111
# File 'lib/wsdl/strictness.rb', line 109

def ==(other)
  other.is_a?(self.class) && to_h == other.to_h
end

#hashInteger



116
117
118
# File 'lib/wsdl/strictness.rb', line 116

def hash
  to_h.hash
end

#inspectString



121
122
123
124
# File 'lib/wsdl/strictness.rb', line 121

def inspect
  settings = to_h.map { |k, v| "#{k}: #{v}" }.join(', ')
  "#<#{self.class} #{settings}>"
end

#to_hHash{Symbol => Boolean}



99
100
101
102
103
104
105
106
# File 'lib/wsdl/strictness.rb', line 99

def to_h
  {
    schema_imports: @schema_imports,
    schema_references: @schema_references,
    operation_overloading: @operation_overloading,
    request_validation: @request_validation
  }
end

#with(**options) ⇒ Strictness

Returns a new Strictness with the specified settings overridden.



89
90
91
92
93
94
95
96
# File 'lib/wsdl/strictness.rb', line 89

def with(**options)
  self.class.new(
    schema_imports: options.fetch(:schema_imports, @schema_imports),
    schema_references: options.fetch(:schema_references, @schema_references),
    operation_overloading: options.fetch(:operation_overloading, @operation_overloading),
    request_validation: options.fetch(:request_validation, @request_validation)
  )
end