Module: Readapt::Error
- Defined in:
- lib/readapt/error.rb
Class Attribute Summary collapse
-
.adapter ⇒ Object
Returns the value of attribute adapter.
Class Method Summary collapse
Instance Method Summary collapse
- #close_message ⇒ Object
- #open_message ⇒ Object
- #opening ⇒ Object
- #procid ⇒ Object
- #receiving(data) ⇒ Object
- #send_event(event, data) ⇒ Object
Class Attribute Details
.adapter ⇒ Object
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/readapt/error.rb', line 6 def adapter @adapter end |
Class Method Details
.procid=(pid) ⇒ Object
47 48 49 |
# File 'lib/readapt/error.rb', line 47 def self.procid= pid @@procid = pid end |
Instance Method Details
#close_message ⇒ Object
59 60 61 |
# File 'lib/readapt/error.rb', line 59 def @@close_message ||= "</readapt-#{procid}>" end |
#open_message ⇒ Object
55 56 57 |
# File 'lib/readapt/error.rb', line 55 def @@open_message ||= "<readapt-#{procid}>" end |
#opening ⇒ Object
9 10 11 |
# File 'lib/readapt/error.rb', line 9 def opening @buffer = '' end |
#procid ⇒ Object
51 52 53 |
# File 'lib/readapt/error.rb', line 51 def procid @@procid end |
#receiving(data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/readapt/error.rb', line 13 def receiving data output = '' data.each_char do |char| @buffer += char if .start_with?(@buffer) || @buffer.start_with?() if @buffer.end_with?() msg = @buffer[.length..-(.length+1)] exit if msg == '__TERMINATE__' Error.adapter.write msg @buffer.clear end else output += @buffer @buffer.clear end end return if output.empty? send_event('output', { output: output, category: 'stderr' }) end |
#send_event(event, data) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/readapt/error.rb', line 36 def send_event event, data obj = { type: 'event', event: event } obj[:body] = data unless data.nil? json = obj.to_json envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}" Error.adapter.write envelope end |