Class: EsHttpClient::WriteableStream
- Inherits:
-
Object
- Object
- EsHttpClient::WriteableStream
- Defined in:
- lib/es_http_client/writeable_stream.rb
Instance Method Summary collapse
- #append(event, expected_version = ExpectedVersion::Any) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(name, connection) ⇒ WriteableStream
constructor
A new instance of WriteableStream.
- #replay_forward(&block) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, connection) ⇒ WriteableStream
Returns a new instance of WriteableStream.
8 9 10 11 |
# File 'lib/es_http_client/writeable_stream.rb', line 8 def initialize(name, connection) @stream_name = name @connection = connection end |
Instance Method Details
#append(event, expected_version = ExpectedVersion::Any) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/es_http_client/writeable_stream.rb', line 26 def append(event, expected_version=ExpectedVersion::Any) @connection.post(Ref.head_of(@stream_name).uri, event, expected_version) true rescue EsHttpClientError => e STDERR.puts e. false end |
#exists? ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'lib/es_http_client/writeable_stream.rb', line 17 def exists? ref = Ref.head_of(@stream_name) @connection.get(ref.uri, ref.etag) true rescue EsHttpClientError => e return false if e.code == 404 raise e end |
#replay_forward(&block) ⇒ Object
34 35 36 |
# File 'lib/es_http_client/writeable_stream.rb', line 34 def replay_forward(&block) StreamEvents.new(@stream_name, @connection).each(&block) end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/es_http_client/writeable_stream.rb', line 13 def to_s @stream_name end |