Class: WatchmonkeyCli::LoopbackConnection
- Inherits:
-
Object
- Object
- WatchmonkeyCli::LoopbackConnection
- Defined in:
- lib/watchmonkey_cli/loopback_connection.rb
Instance Method Summary collapse
- #close! ⇒ Object
- #exec(cmd, chomp = true) ⇒ Object
-
#initialize(id, opts = {}, &initializer) ⇒ LoopbackConnection
constructor
A new instance of LoopbackConnection.
- #name ⇒ Object
- #sync(&block) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(id, opts = {}, &initializer) ⇒ LoopbackConnection
Returns a new instance of LoopbackConnection.
3 4 5 6 7 8 |
# File 'lib/watchmonkey_cli/loopback_connection.rb', line 3 def initialize(id, opts = {}, &initializer) @id = id @opts = {}.merge(opts) # @mutex = Monitor.new initializer.try(:call, @opts) end |
Instance Method Details
#close! ⇒ Object
33 34 |
# File 'lib/watchmonkey_cli/loopback_connection.rb', line 33 def close! end |
#exec(cmd, chomp = true) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/watchmonkey_cli/loopback_connection.rb', line 23 def exec cmd, chomp = true _stdin, _stdouterr, _thread = Open3.popen2e(cmd) _thread.join res = _stdouterr.read chomp ? res.chomp : res ensure _stdin.close rescue false _stdouterr.close rescue false end |
#name ⇒ Object
14 15 16 |
# File 'lib/watchmonkey_cli/loopback_connection.rb', line 14 def name "lo:#{@id}" end |
#sync(&block) ⇒ Object
18 19 20 21 |
# File 'lib/watchmonkey_cli/loopback_connection.rb', line 18 def sync &block # @mutex.synchronize(&block) block.try(:call) end |
#to_s ⇒ Object
10 11 12 |
# File 'lib/watchmonkey_cli/loopback_connection.rb', line 10 def to_s "#<WatchmonkeyCli::LoopbackConnection:#{@id}>" end |