Class: HAProxyManager::HAPSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/haproxy_manager/instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ HAPSocket

Returns a new instance of HAPSocket.



59
60
61
# File 'lib/haproxy_manager/instance.rb', line 59

def initialize(file)
  @file = file
end

Instance Method Details

#execute(cmd) {|response| ... } ⇒ Object

Yields:

  • (response)


63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/haproxy_manager/instance.rb', line 63

def execute(cmd, &block)
  socket = UNIXSocket.new(@file)
  socket.write("#{cmd};")
  response = []
  socket.each do |line|
    data = line.strip
    next if data.empty?
    response << data
  end
  yield response if block_given?
  response
end