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.
- #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(name, type = nil, required = nil) ⇒ Element
constructor
param [String, Symbol] name The name of the element param [String, Symbol] type The optional type of the element.
Constructor Details
#initialize(name, type = nil, required = nil) ⇒ Element
param [String, Symbol] name The name of the element param [String, Symbol] type The optional type of the element
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/response.rb', line 81 def initialize(name, type=nil, required=nil) # sets a documentation placeholder since the response doc is defined at the same time # the response is defined. @doc = Documentation::ElementDoc.new(name) @name = name @type = type @required = !(required==false) @attributes = [] @vectors = [] # 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.
65 66 67 |
# File 'lib/response.rb', line 65 def attributes @attributes end |
#doc ⇒ WSDSL::Documentation::ElementDoc (readonly)
Returns Response element documentation.
73 74 75 |
# File 'lib/response.rb', line 73 def doc @doc end |
#elements ⇒ NilClass, Array<WSDSL::Response::Element> (readonly)
Returns The optional nested elements.
76 77 78 |
# File 'lib/response.rb', line 76 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 |
#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.
69 70 71 |
# File 'lib/response.rb', line 69 def vectors @vectors end |
Instance Method Details
#array(opts) {|Vector| ... } ⇒ Array<WSDSL::Response::Element::Vector>
Defines an array aka vector of elements.
143 144 145 146 147 |
# File 'lib/response.rb', line 143 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
155 156 157 |
# File 'lib/response.rb', line 155 def arrays @vectors end |
#attribute(opts) ⇒ Array<WSDSL::Response::Attribute>
sets a new attribute and returns the entire list of attributes
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/response.rb', line 109 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.
174 175 176 177 178 179 |
# File 'lib/response.rb', line 174 def element(opts={}) el = Element.new(opts[:name], opts[:type], opts[:required]) yield(el) if block_given? @elements ||= [] @elements << el end |