Class: Pry::Shell::Registry

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped
Defined in:
lib/pry/shell/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



12
13
14
15
# File 'lib/pry/shell/registry.rb', line 12

def initialize
  @clients = {}
  @mutex = Mutex.new
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



10
11
12
# File 'lib/pry/shell/registry.rb', line 10

def clients
  @clients
end

#currentObject (readonly)

Returns the value of attribute current.



10
11
12
# File 'lib/pry/shell/registry.rb', line 10

def current
  @current
end

#mutexObject (readonly)

Returns the value of attribute mutex.



10
11
12
# File 'lib/pry/shell/registry.rb', line 10

def mutex
  @mutex
end

Instance Method Details

#connect_to(client) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pry/shell/registry.rb', line 26

def connect_to(client)
  # This thread is necessary because `UI::Session.draw!`
  # puts the main thread into sleep!
  mutex.synchronize do
    return if current

    Thread.start do
      UI::Session.draw!

      @current = client
    end
  end
end

#disconnect(_client) ⇒ Object



40
41
42
43
44
# File 'lib/pry/shell/registry.rb', line 40

def disconnect(_client)
  @current = nil

  UI.restart!
end

#register(id:, name:, host:, pid:, location:) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/pry/shell/registry.rb', line 17

def register(id:, name:, host:, pid:, location:)
  Client.new(id, name, host, pid, location).tap do |client|
    Logger.debug("New client connected - #{client}")

    @clients[id] = client
    connect_to(client) if Shell.configuration.auto_connect
  end
end

#remove(client) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/pry/shell/registry.rb', line 46

def remove(client)
  @clients.delete(client.id)

  if client.current?
    @current = nil
    UI.restart!
  end
end