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
- #opts ⇒ 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.
277 278 279 280 281 282 283 284 |
# File 'lib/response.rb', line 277 def initialize(opts) opts[:required] ||= false @name = opts.delete(:name) if opts.has_key?(:name) @obj_type = opts.delete(:type) if opts.has_key?(:type) @required = opts.has_key?(:required) ? opts[:required] : true @opts = opts @attributes = [] end |
Instance Attribute Details
#attributes ⇒ Object
254 255 256 |
# File 'lib/response.rb', line 254 def attributes @attributes end |
#elements ⇒ NilClass, Array<WSDSL::Response::Element> (readonly)
A vector can have nested elements. This value is nil by default.
262 263 264 |
# File 'lib/response.rb', line 262 def elements @elements end |
#name ⇒ Object (readonly)
242 243 244 |
# File 'lib/response.rb', line 242 def name @name end |
#obj_type ⇒ Object (readonly)
245 246 247 |
# File 'lib/response.rb', line 245 def obj_type @obj_type end |
#opts ⇒ Object (readonly)
248 249 250 |
# File 'lib/response.rb', line 248 def opts @opts end |
#required ⇒ Object
251 252 253 |
# File 'lib/response.rb', line 251 def required @required end |
Instance Method Details
#attribute(opts) ⇒ Object
Sets a vector attribute
290 291 292 293 |
# File 'lib/response.rb', line 290 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.
310 311 312 313 314 315 |
# File 'lib/response.rb', line 310 def element(opts={}) el = Element.new(opts) yield(el) if block_given? @elements ||= [] @elements << el end |