Class: INatGet::App::Server::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/inat-get/app/core/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(detacher, socket_path, wait_answer = true) ⇒ Proxy

Returns a new instance of Proxy.



76
77
78
79
80
# File 'lib/inat-get/app/core/server.rb', line 76

def initialize detacher, socket_path, wait_answer = true
  @detacher = detacher
  @socket_path = socket_path
  @wait_answer = wait_answer
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, **kwargs) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/inat-get/app/core/server.rb', line 95

def method_missing sym, *args, **kwargs
  kwargs[:_sender_pid] ||= ::Process::pid
  msg = {
    method: sym,
    args: args,
    kwargs: kwargs
  }
  socket = ::UNIXSocket::new @socket_path
  ::Marshal.dump msg, socket
  result = @wait_answer ? ::Marshal.load(socket) : true
  socket.close
  result
rescue => e
  # pp e
  { status: :error, error: e.message }
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/inat-get/app/core/server.rb', line 91

def alive?
  @detacher.alive?
end

#closeObject



82
83
84
85
# File 'lib/inat-get/app/core/server.rb', line 82

def close
  self.quit
  @detacher.join
end

#pidObject



87
88
89
# File 'lib/inat-get/app/core/server.rb', line 87

def pid
  @detacher.pid
end