Class: Pry::Shell::Registry
- Inherits:
-
Object
- Object
- Pry::Shell::Registry
- Includes:
- DRb::DRbUndumped
- Defined in:
- lib/pry/shell/registry.rb
Instance Attribute Summary collapse
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Instance Method Summary collapse
- #connect_to(client) ⇒ Object
- #disconnect(_client) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(id:, name:, host:, pid:, location:) ⇒ Object
- #remove(client) ⇒ Object
Constructor Details
#initialize ⇒ Registry
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
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
10 11 12 |
# File 'lib/pry/shell/registry.rb', line 10 def clients @clients end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
10 11 12 |
# File 'lib/pry/shell/registry.rb', line 10 def current @current end |
#mutex ⇒ Object (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 |