Method: WSDSL::Response::Element#attribute

Defined in:
lib/response.rb

#attribute(opts, extra_opts = {}) ⇒ Array<WSDSL::Response::Attribute>

sets a new attribute and returns the entire list of attributes

Examples:

Creation of a response attribute called ‘best_lap_time’

service.response do |response|
 response.element(:name => "my_stats", :type => 'Leaderboard') do |e|
   e.attribute "best_lap_time"       => :float,    :doc => "Best lap time in seconds."
 end
end

Options Hash (opts):

  • attribute_name (String, Symbol)

    The name of the attribute, the value being the type

  • :doc (String, Symbol)

    The attribute documentation

  • :mock (String, Symbol)

    An optional mock value used by service related tools

Raises:

  • (ArgumentError)

Since:

  • 0.0.3



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/response.rb', line 176

def attribute(opts, extra_opts={})
  raise ArgumentError unless opts.is_a?(Hash) && extra_opts.is_a?(Hash)
  new_attribute = Attribute.new(opts, extra_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.merge!(extra_opts).has_key?(:doc)
    @doc.attribute(new_attribute.name, opts[:doc])
  end
  @attributes
end