class HalClient::RepresentationSet

A collection HAL representations

Attributes

reprs[R]

Public Class Methods

new(reprs) click to toggle source
# File lib/hal_client/representation_set.rb, line 10
def initialize(reprs)
  @reprs = reprs
end

Public Instance Methods

form(form_id="default") click to toggle source

Returns the specified `Form`

form_id - the string or symbol id of the form of interest. Default: `“default”`

Raises `KeyError` if the specified form doesn't exist, or if there are duplicates.

# File lib/hal_client/representation_set.rb, line 81
def form(form_id="default")
  self
    .map { |r|
      begin
        r.form(form_id)
      rescue KeyError
        nil
      end }
    .compact
    .tap do |fs|
      raise KeyError, "Duplicate `#{form_id}` forms exist" if fs.count > 1
    end
    .first
end
patch(data, options={}) click to toggle source

Patch a `Representation` or `String` to the resource.

NOTE: This only works for a single representation.

data - a `String` or an object that responds to `#to_hal` options - set of options to pass to `HalClient#patch`

# File lib/hal_client/representation_set.rb, line 70
def patch(data, options={})
  raise NotImplementedError, "We only patchs to singular resources." if count > 1
  first.patch(data, options)
end
post(data, options={}) click to toggle source

Post a `Representation` or `String` to the resource.

NOTE: This only works for a single representation.

data - a `String` or an object that responds to `#to_hal` options - set of options to pass to `HalClient#post`

# File lib/hal_client/representation_set.rb, line 48
def post(data, options={})
  raise NotImplementedError, "We only posts to singular resources." if count > 1
  first.post(data, options)
end
put(data, options={}) click to toggle source

Put a `Representation` or `String` to the resource.

NOTE: This only works for a single representation.

data - a `String` or an object that responds to `#to_hal` options - set of options to pass to `HalClient#put`

# File lib/hal_client/representation_set.rb, line 59
def put(data, options={})
  raise NotImplementedError, "We only puts to singular resources." if count > 1
  first.put(data, options)
end