Class: WSDSL::Response::Element
- Inherits:
-
Object
- Object
- WSDSL::Response::Element
- Defined in:
- lib/response.rb
Overview
The Response element class describing each element of a service response. Instances are usually not instiated directly but via the Response#element accessor.
Defined Under Namespace
Instance Attribute Summary collapse
-
#attributes ⇒ Array<WSDSL::Response::Element::Attribute>
readonly
An array of attributes.
-
#doc ⇒ WSDSL::Documentation::ElementDoc
readonly
Response element documentation.
-
#elements ⇒ NilClass, Array<WSDSL::Response::Element>
readonly
The optional nested elements.
-
#name ⇒ String, #to_s
readonly
The name of the element.
- #opts ⇒ Object readonly
- #required ⇒ Object readonly
- #type ⇒ Object readonly
-
#vectors ⇒ Array
readonly
An array of vectors/arrays.
Instance Method Summary collapse
-
#array(opts) {|Vector| ... } ⇒ Array<WSDSL::Response::Element::Vector>
Defines an array aka vector of elements.
-
#arrays ⇒ Array<WSDSL::Response::Element::Vector>
Returns the arrays/vectors contained in the response.
-
#attribute(opts) ⇒ Array<WSDSL::Response::Attribute>
sets a new attribute and returns the entire list of attributes.
-
#element(opts = {}) {|WSDSL::Response::Element| ... } ⇒ Array<WSDSL::Response::Element>
Defines a new element and yields the content of an optional block Each new element is then stored in the elements array.
-
#initialize(opts = {}) ⇒ Element
constructor
param [String, Symbol] name The name of the element param [String, Symbol] type The optional type of the element.
Constructor Details
#initialize(opts = {}) ⇒ Element
param [String, Symbol] name The name of the element param [String, Symbol] type The optional type of the element
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/response.rb', line 84 def initialize(opts={}) opts[:type] ||= nil opts[:required] = nil if !opts.has_key?(:required) # sets a documentation placeholder since the response doc is defined at the same time # the response is defined. @name = opts.delete(:name) if(opts.has_key?(:name)) @doc = Documentation::ElementDoc.new(@name) @type = opts.delete(:type) if(opts.has_key?(:type)) @required = opts.has_key?(:required) ? opts[:required] : true @attributes = [] @vectors = [] @opts = opts # we don't need to initialize the nested elements, by default they should be nil end |
Instance Attribute Details
#attributes ⇒ Array<WSDSL::Response::Element::Attribute> (readonly)
Returns An array of attributes.
68 69 70 |
# File 'lib/response.rb', line 68 def attributes @attributes end |
#doc ⇒ WSDSL::Documentation::ElementDoc (readonly)
Returns Response element documentation.
76 77 78 |
# File 'lib/response.rb', line 76 def doc @doc end |
#elements ⇒ NilClass, Array<WSDSL::Response::Element> (readonly)
Returns The optional nested elements.
79 80 81 |
# File 'lib/response.rb', line 79 def elements @elements end |
#name ⇒ String, #to_s (readonly)
Returns The name of the element.
55 56 57 |
# File 'lib/response.rb', line 55 def name @name end |
#opts ⇒ Object (readonly)
64 65 66 |
# File 'lib/response.rb', line 64 def opts @opts end |
#required ⇒ Object (readonly)
58 59 60 |
# File 'lib/response.rb', line 58 def required @required end |
#type ⇒ Object (readonly)
61 62 63 |
# File 'lib/response.rb', line 61 def type @type end |
#vectors ⇒ Array (readonly)
Returns An array of vectors/arrays.
72 73 74 |
# File 'lib/response.rb', line 72 def vectors @vectors end |
Instance Method Details
#array(opts) {|Vector| ... } ⇒ Array<WSDSL::Response::Element::Vector>
Defines an array aka vector of elements.
150 151 152 153 154 |
# File 'lib/response.rb', line 150 def array(opts) vector = Vector.new(opts) yield(vector) if block_given? @vectors << vector end |
#arrays ⇒ Array<WSDSL::Response::Element::Vector>
Returns the arrays/vectors contained in the response. This is an alias to access @vectors
162 163 164 |
# File 'lib/response.rb', line 162 def arrays @vectors end |
#attribute(opts) ⇒ Array<WSDSL::Response::Attribute>
sets a new attribute and returns the entire list of attributes
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/response.rb', line 116 def attribute(opts) raise ArgumentError unless opts.is_a?(Hash) # extract the documentation part and add it where it belongs new_attribute = Attribute.new(opts) @attributes << new_attribute # document the attribute if description available # we might want to have a placeholder message when a response attribute isn't defined if opts.has_key?(:doc) @doc.attribute(new_attribute.name, opts[:doc]) end @attributes end |
#element(opts = {}) {|WSDSL::Response::Element| ... } ⇒ Array<WSDSL::Response::Element>
Defines a new element and yields the content of an optional block Each new element is then stored in the elements array.
181 182 183 184 185 186 |
# File 'lib/response.rb', line 181 def element(opts={}) el = Element.new(opts) yield(el) if block_given? @elements ||= [] @elements << el end |