class WADL::RepresentationFormat

Constants

FORM_TYPES

Public Instance Methods

%(values) click to toggle source

Creates a representation by plugging a set of parameters into a representation format.

# File lib/wadl/representation_format.rb, line 48
def %(values)
  unless is_form_representation?
    raise "wadl can't instantiate a representation of type #{mediaType}"
  end

  representation = []

  params.each { |param|
    name = param.name

    if param.fixed
      p_values = [param.fixed]
    elsif p_values = values[name] || values[name.to_sym]
      p_values = [p_values] if !param.repeating? || !p_values.respond_to?(:each) || p_values.respond_to?(:to_str)
    else
      raise ArgumentError, "Your proposed representation is missing a value for #{param.name}" if param.required?
    end

    p_values.each { |v| representation << "#{CGI.escape(name)}=#{CGI.escape(v.to_s)}" } if p_values
  }

  representation.join('&')
end
is_form_representation?() click to toggle source
# File lib/wadl/representation_format.rb, line 42
def is_form_representation?
  FORM_TYPES.include?(mediaType)
end