Class: NREPL::Client
- Inherits:
-
Object
- Object
- NREPL::Client
- Defined in:
- lib/nrepl-lazuli/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #closed? ⇒ Boolean
-
#initialize(port: DEFAULT_PORT, host: DEFAULT_HOST) ⇒ Client
constructor
A new instance of Client.
- #read ⇒ Object
- #register_session ⇒ Object
- #rpc(msg) ⇒ Object
- #stop ⇒ Object
- #write(msg) ⇒ Object
Constructor Details
#initialize(port: DEFAULT_PORT, host: DEFAULT_HOST) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 |
# File 'lib/nrepl-lazuli/client.rb', line 10 def initialize(port: DEFAULT_PORT, host: DEFAULT_HOST) @port = port @host = host @socket = TCPSocket.new(@host, @port) @bencode = BEncode.new(@socket) @last_id = 0 end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/nrepl-lazuli/client.rb', line 8 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/nrepl-lazuli/client.rb', line 8 def port @port end |
Instance Method Details
#closed? ⇒ Boolean
62 63 64 |
# File 'lib/nrepl-lazuli/client.rb', line 62 def closed? @socket.nil? end |
#read ⇒ Object
50 51 52 |
# File 'lib/nrepl-lazuli/client.rb', line 50 def read @bencode.parse! end |
#register_session ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/nrepl-lazuli/client.rb', line 54 def register_session write('op' => 'clone') msg = read! raise ArgumentError, "failed to create session" unless msg['new_session'] msg['new_session'] end |
#rpc(msg) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nrepl-lazuli/client.rb', line 26 def rpc(msg) id = msg["id"] || msg[:id] if(!id) @last_id += 1 id = "autogen_#@last_id" msg = msg.merge('id' => id) end write(msg) Timeout.timeout(10) do loop do ret = read if(ret["id"] == id) break ret end end end end |
#stop ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/nrepl-lazuli/client.rb', line 18 def stop unless closed? @socket.close @socket = nil @bencode = nil end end |