Class: WSDSL::Response::Element::Vector
- Inherits:
-
Object
- Object
- WSDSL::Response::Element::Vector
- Defined in:
- lib/response.rb
Overview
Array of objects inside an element
Instance Attribute Summary collapse
- #attributes ⇒ Object
-
#elements ⇒ NilClass, Array<WSDSL::Response::Element>
readonly
A vector can have nested elements.
- #name ⇒ Object readonly
- #obj_type ⇒ Object readonly
- #required ⇒ Object
Instance Method Summary collapse
-
#attribute(opts) ⇒ Object
Sets a vector attribute.
-
#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) ⇒ Vector
constructor
Initialize a Vector object, think about it as an array of objects of a certain type.
Constructor Details
#initialize(opts) ⇒ Vector
Initialize a Vector object, think about it as an array of objects of a certain type. It is recommended to passthe type argument as a string so the constant doesn’t need to be resolved. In other words, if you say you are creating a vector of Foo objects, the Foo class doesn’t need to be loaded yet. That makes service parsing easier and avoids dependency challenges.
267 268 269 270 271 272 |
# File 'lib/response.rb', line 267 def initialize(opts) @name = opts[:name] @obj_type = opts[:type] @required = !(opts[:required] == false) @attributes = [] end |
Instance Attribute Details
#attributes ⇒ Object
244 245 246 |
# File 'lib/response.rb', line 244 def attributes @attributes end |
#elements ⇒ NilClass, Array<WSDSL::Response::Element> (readonly)
A vector can have nested elements. This value is nil by default.
252 253 254 |
# File 'lib/response.rb', line 252 def elements @elements end |
#name ⇒ Object (readonly)
235 236 237 |
# File 'lib/response.rb', line 235 def name @name end |
#obj_type ⇒ Object (readonly)
238 239 240 |
# File 'lib/response.rb', line 238 def obj_type @obj_type end |
#required ⇒ Object
241 242 243 |
# File 'lib/response.rb', line 241 def required @required end |
Instance Method Details
#attribute(opts) ⇒ Object
Sets a vector attribute
278 279 280 281 |
# File 'lib/response.rb', line 278 def attribute(opts) raise ArgumentError unless opts.is_a?(Hash) @attributes << Attribute.new(opts) 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.
298 299 300 301 302 303 |
# File 'lib/response.rb', line 298 def element(opts={}) el = Element.new(opts[:name], opts[:type], opts[:required]) yield(el) if block_given? @elements ||= [] @elements << el end |