Class: Beachcomber::Session

Inherits:
Object
  • Object
show all
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

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

#closeObject

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.

Parameters:

  • key (String)

    e.g. “git.branch” or “git”

  • path (String, nil) (defaults to: nil)

    optional working-directory override

Returns:



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

#listResult

Lists available providers.

Returns:



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.

Parameters:

  • key (String)
  • path (String, nil) (defaults to: nil)


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.

Parameters:

  • path (String)


31
32
33
34
# File 'lib/beachcomber/client.rb', line 31

def set_context(path)
  roundtrip({ op: 'context', path: path })
  nil
end

#statusResult

Returns daemon status.

Returns:



68
69
70
# File 'lib/beachcomber/client.rb', line 68

def status
  roundtrip({ op: 'status' })
end