Module: Readapt::Output

Defined in:
lib/readapt/output.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.adapterObject

Returns the value of attribute adapter.



4
5
6
# File 'lib/readapt/output.rb', line 4

def adapter
  @adapter
end

Instance Method Details

#receiving(data) ⇒ Object



7
8
9
10
11
12
# File 'lib/readapt/output.rb', line 7

def receiving data
  send_event('output', {
    output: data.force_encoding('utf-8'),
    category: 'stdout'
  })
end

#send_event(event, data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/readapt/output.rb', line 14

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}"
  Output.adapter.write envelope
end