Class: Routemaster::Responses::HateoasEnumerableResponse

Inherits:
HateoasResponse show all
Includes:
Enumerable
Defined in:
lib/routemaster/responses/hateoas_enumerable_response.rb

Overview

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.

Instance Attribute Summary

Attributes inherited from HateoasResponse

#response

Instance Method Summary collapse

Methods inherited from HateoasResponse

#body_without_links, #has?, #initialize, #method_missing

Methods included from Forwardable

_compile_method

Constructor Details

This class inherits a constructor from Routemaster::Responses::HateoasResponse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Routemaster::Responses::HateoasResponse

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
21
# File 'lib/routemaster/responses/hateoas_enumerable_response.rb', line 17

def each(&block)
  each_page do |items|
    items.each(&block)
  end
end

#each_pageObject



23
24
25
26
27
28
29
30
# 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