Class: WADL::RepresentationFormat

Inherits:
HasDocs show all
Defined in:
lib/wadl/representation_format.rb

Direct Known Subclasses

FaultFormat

Constant Summary

Constant Summary

Constants inherited from CheapSchema

CheapSchema::ATTRIBUTES

Instance Attribute Summary

Attributes inherited from CheapSchema

#attributes, #href, #index_key, #parent

Instance Method Summary (collapse)

Methods inherited from HasDocs

#define_singleton

Methods inherited from CheapSchema

as_collection, as_member, contents_are_mixed_data, #dereference, #dereference_with_context, dereferencing_attr_accessor, dereferencing_instance_accessor, #each_attribute, #each_collection, #each_member, from_element, has_attributes, has_many, has_one, has_required, in_document, inherit, inherited, init, #initialize, #matches?, may_be_reference, may_be_reference?, #paths, #to_s

Constructor Details

This class inherits a constructor from WADL::CheapSchema

Instance Method Details

- (Object) %(values)

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wadl/representation_format.rb', line 47

def %(values)
  unless mediaType == 'application/x-www-form-urlencoded'
    raise "wadl.rb 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

- (Boolean) is_form_representation?

Returns:

  • (Boolean)


41
42
43
# File 'lib/wadl/representation_format.rb', line 41

def is_form_representation?
  mediaType == 'application/x-www-form-urlencoded' || mediaType == 'multipart/form-data'
end