Class: EsHttpClient::StreamEvents

Inherits:
Object
  • Object
show all
Defined in:
lib/es_http_client/stream_events.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, connection) ⇒ StreamEvents

Returns a new instance of StreamEvents.



7
8
9
10
# File 'lib/es_http_client/stream_events.rb', line 7

def initialize(name, connection)
  @connection = connection
  @latest_ref = Ref.head_of(name)
end

Instance Method Details

#each(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/es_http_client/stream_events.rb', line 12

def each(&block)
  page = read_stream_page(@latest_ref.uri)
  last = page.last
  page = read_stream_page(last) if last
  loop do
    break unless page.has_entries?
    page.each_event(&block)
    next_page = page.previous
    break unless next_page
    page = read_stream_page(next_page)
  end
  return @latest_ref
end