Module: Readapt::Adapter
- Includes:
- Backport::Adapter
- Defined in:
- lib/readapt/adapter.rb
Constant Summary collapse
- @@debugger =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #close_message ⇒ Object
- #closing ⇒ Object
- #format(result) ⇒ Object
- #open_message ⇒ Object
- #opening ⇒ Object
- #procid ⇒ Object
- #receiving(data) ⇒ Object
- #update(event, data) ⇒ Object
Class Method Details
.host(debugger) ⇒ Object
11 12 13 |
# File 'lib/readapt/adapter.rb', line 11 def self.host debugger @@debugger = debugger end |
.procid=(pid) ⇒ Object
15 16 17 |
# File 'lib/readapt/adapter.rb', line 15 def self.procid= pid @@procid = pid end |
Instance Method Details
#close_message ⇒ Object
27 28 29 |
# File 'lib/readapt/adapter.rb', line 27 def @@close_message ||= "</readapt-#{procid}>" end |
#closing ⇒ Object
43 44 45 |
# File 'lib/readapt/adapter.rb', line 43 def closing @@debugger.delete_observer(self) end |
#format(result) ⇒ Object
31 32 33 |
# File 'lib/readapt/adapter.rb', line 31 def format result write_line result.to_protocol.to_json end |
#open_message ⇒ Object
23 24 25 |
# File 'lib/readapt/adapter.rb', line 23 def @@open_message ||= "<readapt-#{procid}>" end |
#opening ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/readapt/adapter.rb', line 35 def opening @@debugger.add_observer self @data_reader = DataReader.new @data_reader. do || process end end |
#procid ⇒ Object
19 20 21 |
# File 'lib/readapt/adapter.rb', line 19 def procid @@procid end |
#receiving(data) ⇒ Object
47 48 49 |
# File 'lib/readapt/adapter.rb', line 47 def receiving data @data_reader.receive data end |
#update(event, data) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/readapt/adapter.rb', line 51 def update 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}#{}" write envelope write "#{}__TERMINATE__#{}" if event == 'terminated' end |