class Routemaster::Responses::HateoasEnumerableResponse

Yields all resources listed in a collection endpoint in a non-greedy, non-recursive manner.

Each yielded resource is a future; synchronous requests are performed for each page.

NB: the first named collection in the _links section of the payload will be enumerated. Any other named collections will simply be ignored.

Public Instance Methods

each(&block) click to toggle source
# File lib/routemaster/responses/hateoas_enumerable_response.rb, line 17
def each(&block)
  each_page do |items|
    items.each(&block)
  end
end
each_page() { |_page_items(current_page)| ... } click to toggle source
# File lib/routemaster/responses/hateoas_enumerable_response.rb, line 23
def each_page
  current_page = self
  loop do
    yield _page_items(current_page)
    break unless current_page.has?(:next)
    current_page = current_page.next.index
  end
end

Private Instance Methods

_page_items(page) click to toggle source
# File lib/routemaster/responses/hateoas_enumerable_response.rb, line 40
def _page_items(page)
  page.body._links.fetch(_resource_name).map do |link|
    @client.fget(link.href)
  end
end
_resource_name() click to toggle source
# File lib/routemaster/responses/hateoas_enumerable_response.rb, line 34
def _resource_name
  _links.find { |k,v|
    !%w[curies self].include?(k) && v.kind_of?(Array)
  }.first
end