Class: Wasabi::Document
- Inherits:
-
Object
- Object
- Wasabi::Document
- Defined in:
- lib/wasabi/document.rb
Overview
Wasabi::Document
Represents a WSDL document.
Constant Summary collapse
- ELEMENT_FORM_DEFAULTS =
[:unqualified, :qualified]
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#endpoint ⇒ Object
Returns the SOAP endpoint.
-
#namespace ⇒ Object
Returns the target namespace.
Class Method Summary collapse
-
.validate_element_form_default!(value) ⇒ Object
Validates if a given
value
is a valid elementFormDefault value.
Instance Method Summary collapse
-
#document? ⇒ Boolean
Returns whether a
document
was set. -
#element_form_default ⇒ Object
Returns the value of elementFormDefault.
-
#element_form_default=(value) ⇒ Object
Sets the elementFormDefault value.
-
#initialize(document = nil) ⇒ Document
constructor
Accepts a WSDL
document
to parse. -
#operations ⇒ Object
Returns a map of SOAP operations.
-
#parser ⇒ Object
Parses the WSDL document and returns the
Wasabi::Parser
. -
#soap_action(key) ⇒ Object
Returns the SOAP action for a given
key
. -
#soap_actions ⇒ Object
Returns a list of available SOAP actions.
-
#soap_input(key) ⇒ Object
Returns the SOAP input for a given
key
. - #type_definitions ⇒ Object
- #type_namespaces ⇒ Object
-
#user_defined(namespace) ⇒ Object
Returns whether the given
namespace
was defined manually. -
#xml ⇒ Object
Returns the raw WSDL document.
-
#xml? ⇒ Boolean
Returns whether there is a WSDL document to parse.
Constructor Details
#initialize(document = nil) ⇒ Document
Accepts a WSDL document
to parse.
23 24 25 |
# File 'lib/wasabi/document.rb', line 23 def initialize(document = nil) self.document = document end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
27 28 29 |
# File 'lib/wasabi/document.rb', line 27 def document @document end |
#endpoint ⇒ Object
Returns the SOAP endpoint.
35 36 37 |
# File 'lib/wasabi/document.rb', line 35 def endpoint @endpoint ||= parser.endpoint end |
#namespace ⇒ Object
Returns the target namespace.
43 44 45 |
# File 'lib/wasabi/document.rb', line 43 def namespace @namespace ||= parser.namespace end |
Class Method Details
.validate_element_form_default!(value) ⇒ Object
Validates if a given value
is a valid elementFormDefault value. Raises an ArgumentError
if the value is not valid.
15 16 17 18 19 20 |
# File 'lib/wasabi/document.rb', line 15 def self.validate_element_form_default!(value) return if ELEMENT_FORM_DEFAULTS.include?(value) raise ArgumentError, "Invalid value for elementFormDefault: #{value}\n" + "Must be one of: #{ELEMENT_FORM_DEFAULTS.inspect}" end |
Instance Method Details
#document? ⇒ Boolean
Returns whether a document
was set.
30 31 32 |
# File 'lib/wasabi/document.rb', line 30 def document? !!document end |
#element_form_default ⇒ Object
Returns the value of elementFormDefault.
51 52 53 |
# File 'lib/wasabi/document.rb', line 51 def element_form_default @element_form_default ||= xml? ? parser.element_form_default : :unqualified end |
#element_form_default=(value) ⇒ Object
Sets the elementFormDefault value.
56 57 58 59 |
# File 'lib/wasabi/document.rb', line 56 def element_form_default=(value) self.class.validate_element_form_default!(value) @element_form_default = value end |
#operations ⇒ Object
Returns a map of SOAP operations.
77 78 79 |
# File 'lib/wasabi/document.rb', line 77 def operations @operations ||= parser.operations end |
#parser ⇒ Object
Parses the WSDL document and returns the Wasabi::Parser
.
124 125 126 |
# File 'lib/wasabi/document.rb', line 124 def parser @parser ||= guard_parse && parse end |
#soap_action(key) ⇒ Object
Returns the SOAP action for a given key
.
67 68 69 |
# File 'lib/wasabi/document.rb', line 67 def soap_action(key) operations[key][:action] if operations[key] end |
#soap_actions ⇒ Object
Returns a list of available SOAP actions.
62 63 64 |
# File 'lib/wasabi/document.rb', line 62 def soap_actions @soap_actions ||= parser.operations.keys end |
#soap_input(key) ⇒ Object
Returns the SOAP input for a given key
.
72 73 74 |
# File 'lib/wasabi/document.rb', line 72 def soap_input(key) operations[key][:input] if operations[key] end |
#type_definitions ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/wasabi/document.rb', line 92 def type_definitions @type_definitions ||= begin result = [] parser.types.each do |type, info| (info.keys - [:namespace]).each do |field| field_type = info[field][:type] tag, namespace = field_type.split(":").reverse result << [[type, field], tag] if user_defined(namespace) end end if document? result end end |
#type_namespaces ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/wasabi/document.rb', line 81 def type_namespaces @type_namespaces ||= begin namespaces = [] parser.types.each do |type, info| namespaces << [[type], info[:namespace]] (info.keys - [:namespace]).each { |field| namespaces << [[type, field], info[:namespace]] } end if document? namespaces end end |
#user_defined(namespace) ⇒ Object
Returns whether the given namespace
was defined manually.
107 108 109 110 |
# File 'lib/wasabi/document.rb', line 107 def user_defined(namespace) uri = parser.namespaces[namespace] !(uri =~ %r{^http://schemas.xmlsoap.org} || uri =~ %r{^http://www.w3.org}) end |
#xml ⇒ Object
Returns the raw WSDL document. Can be used as a hook to extend the library.
114 115 116 |
# File 'lib/wasabi/document.rb', line 114 def xml @xml ||= document end |
#xml? ⇒ Boolean
Returns whether there is a WSDL document to parse.
119 120 121 |
# File 'lib/wasabi/document.rb', line 119 def xml? xml.kind_of?(String) end |