Class: HalClient::RepresentationSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/hal_client/representation_set.rb

Overview

A collection HAL representations

Instance Method Summary collapse

Constructor Details

#initialize(reprs) ⇒ RepresentationSet



10
11
12
# File 'lib/hal_client/representation_set.rb', line 10

def initialize(reprs)
  @reprs = reprs
end

Instance Method Details

#has_related?(link_rel) ⇒ Boolean

Returns true if any member representation contains a link (including embedded links) whose rel is link_rel.

link_rel - The link rel of interest



37
38
39
# File 'lib/hal_client/representation_set.rb', line 37

def has_related?(link_rel)
  any? {|it| it.has_related?(link_rel) }
end

#post(data, options = {}) ⇒ Object

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`

Raises:

  • (NotImplementedError)


47
48
49
50
# File 'lib/hal_client/representation_set.rb', line 47

def post(data, options={})
  raise NotImplementedError, "We only posts to singular resources." if count > 1
  first.post(data, options)
end

Returns representations of resources related via the specified

link rel or the specified default value.

name_or_rel - The name of property or link rel of interest options - optional keys and values with which to expand any

templated links that are encountered

default_proc - an option proc that will be called with name

to produce default value if the specified property or link does not
exist

Raises KeyError if the specified link does not exist

and no default_proc is provided.

Raises:

  • (KeyError)


28
29
30
31
# File 'lib/hal_client/representation_set.rb', line 28

def related(link_rel, options={})
  raise KeyError unless has_related? link_rel
  RepresentationSet.new flat_map{|it| it.related(link_rel, options){[]}.to_a }
end