Class: DreddHooks::Server::Buffer
- Inherits:
-
Object
- Object
- DreddHooks::Server::Buffer
- Defined in:
- lib/dredd_hooks/server/buffer.rb
Overview
Store JSON messages or part of them
Instance Method Summary collapse
- #<<(string) ⇒ Object
- #any_message? ⇒ Boolean
-
#flush! ⇒ Object
Empty the buffer.
-
#initialize(message_delimiter) ⇒ Buffer
constructor
A new instance of Buffer.
- #unshift_messages ⇒ Object
Constructor Details
#initialize(message_delimiter) ⇒ Buffer
Returns a new instance of Buffer.
9 10 11 12 |
# File 'lib/dredd_hooks/server/buffer.rb', line 9 def initialize() flush! @message_delimiter = end |
Instance Method Details
#<<(string) ⇒ Object
23 24 25 |
# File 'lib/dredd_hooks/server/buffer.rb', line 23 def <<(string) @content += string end |
#any_message? ⇒ Boolean
27 28 29 |
# File 'lib/dredd_hooks/server/buffer.rb', line 27 def @content.include? @message_delimiter end |
#flush! ⇒ Object
Empty the buffer.
Returns the buffer content String.
17 18 19 20 21 |
# File 'lib/dredd_hooks/server/buffer.rb', line 17 def flush! content = @content @content = "" content end |
#unshift_messages ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dredd_hooks/server/buffer.rb', line 31 def flush!. split(@message_delimiter). inject([]) { |, | begin .push JSON.parse() rescue JSON::ParserError # If the message after the delimiter is not parseable JSON, # then it's a chunk of the next message, and should be put back # into the buffer. @content += end } end |