Class: Kubeclient::Common::WatchStream
- Inherits:
-
Object
- Object
- Kubeclient::Common::WatchStream
- Defined in:
- lib/kubeclient/watch_stream.rb
Overview
HTTP Stream used to watch changes on entities
Instance Method Summary collapse
- #each ⇒ Object
- #finish ⇒ Object
-
#initialize(uri, http_options, format: :json) ⇒ WatchStream
constructor
A new instance of WatchStream.
Constructor Details
#initialize(uri, http_options, format: :json) ⇒ WatchStream
Returns a new instance of WatchStream.
7 8 9 10 11 12 |
# File 'lib/kubeclient/watch_stream.rb', line 7 def initialize(uri, , format: :json) @uri = uri @http_client = nil @http_options = @format = format end |
Instance Method Details
#each ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kubeclient/watch_stream.rb', line 14 def each @finished = false @http_client = build_client response = @http_client.request(:get, @uri, ) unless response.code < 300 fail KubeException.new(response.code, response.reason, response) end buffer = '' response.body.each do |chunk| buffer << chunk while (line = buffer.slice!(/.+\n/)) yield @format == :json ? WatchNotice.new(JSON.parse(line)) : line.chomp end end rescue IOError raise unless @finished end |
#finish ⇒ Object
34 35 36 37 |
# File 'lib/kubeclient/watch_stream.rb', line 34 def finish @finished = true @http_client.close unless @http_client.nil? end |