Class: Beachcomber::Session
- Inherits:
-
Object
- Object
- Beachcomber::Session
- Defined in:
- lib/beachcomber/client.rb
Overview
Session holds a persistent connection to the daemon and sends multiple requests over the same socket.
Obtain a Session via Client#session:
client.session do |s|
s.set_context('/repo')
r = s.get('git.branch')
end
Not thread-safe; use one session per thread.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the underlying socket connection.
-
#get(key, path: nil) ⇒ Result
Reads a cached value.
-
#initialize(socket, timeout) ⇒ Session
constructor
A new instance of Session.
-
#list ⇒ Result
Lists available providers.
-
#poke(key, path: nil) ⇒ Object
Forces the daemon to recompute a provider/key.
-
#set_context(path) ⇒ Object
Sets the default path for subsequent queries on this connection.
-
#status ⇒ Result
Returns daemon status.
Constructor Details
#initialize(socket, timeout) ⇒ Session
Returns a new instance of Session.
23 24 25 26 |
# File 'lib/beachcomber/client.rb', line 23 def initialize(socket, timeout) @socket = socket @timeout = timeout end |
Instance Method Details
#close ⇒ Object
Closes the underlying socket connection.
73 74 75 |
# File 'lib/beachcomber/client.rb', line 73 def close @socket.close unless @socket.closed? end |
#get(key, path: nil) ⇒ Result
Reads a cached value.
41 42 43 44 45 |
# File 'lib/beachcomber/client.rb', line 41 def get(key, path: nil) req = { op: 'get', key: key } req[:path] = path if path roundtrip(req) end |
#list ⇒ Result
Lists available providers.
61 62 63 |
# File 'lib/beachcomber/client.rb', line 61 def list roundtrip({ op: 'list' }) end |
#poke(key, path: nil) ⇒ Object
Forces the daemon to recompute a provider/key.
51 52 53 54 55 56 |
# File 'lib/beachcomber/client.rb', line 51 def poke(key, path: nil) req = { op: 'poke', key: key } req[:path] = path if path roundtrip(req) nil end |
#set_context(path) ⇒ Object
Sets the default path for subsequent queries on this connection.
31 32 33 34 |
# File 'lib/beachcomber/client.rb', line 31 def set_context(path) roundtrip({ op: 'context', path: path }) nil end |
#status ⇒ Result
Returns daemon status.
68 69 70 |
# File 'lib/beachcomber/client.rb', line 68 def status roundtrip({ op: 'status' }) end |