Class: Yabeda::Puma::Plugin::Statistics::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/yabeda/puma/plugin/statistics/fetcher.rb

Class Method Summary collapse

Class Method Details

.callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yabeda/puma/plugin/statistics/fetcher.rb', line 9

def self.call
  control_url = Yabeda::Puma::Plugin.control_url

  body = if control_url.start_with? "unix://"
    path = control_url.gsub("unix://", '')
    Socket.unix(path, &socket_block)
  elsif control_url.start_with? "tcp://"
    host, port = control_url.match(/^tcp:\/\/([a-z0-9\-._~%]+):([0-9]+)/).captures
    Socket.tcp(host, port, &socket_block)
  else
    raise ArgumentError.new("Unknown puma control url type #{control_url}")
  end

  JSON.parse(body.split("\n").last)
end