class ExecJS::FastNode::ExternalPipedRuntime::VMCommand

Public Class Methods

new(socket_path, cmd, arguments) click to toggle source
# File lib/execjs/fastnode/external_piped_runtime.rb, line 14
def initialize(socket_path, cmd, arguments)
  @socket_path = socket_path.to_s
  @cmd = cmd
  @arguments = arguments
end

Public Instance Methods

execute() click to toggle source
# File lib/execjs/fastnode/external_piped_runtime.rb, line 20
def execute
  sock = Net::BufferedIO.new(socket)

  request = Net::HTTP::Post.new("/")
  request['Connection'] = 'close'
  request['Content-Type'] = 'application/json'
  request.body = contents
  request.exec(sock, "1.1", "/")

  begin
    response = Net::HTTPResponse.read_new(sock)
  end while response.kind_of?(Net::HTTPContinue)

  response.reading_body(sock, request.response_body_permitted?) { }
  sock.close

  parse(response.body)
end

Private Instance Methods

contents() click to toggle source
# File lib/execjs/fastnode/external_piped_runtime.rb, line 45
def contents
  ::JSON.generate({cmd: @cmd, args: @arguments})
end
parse(body) click to toggle source
# File lib/execjs/fastnode/external_piped_runtime.rb, line 49
def parse(body)
  ::JSON.parse(body, create_additions: false)
end
socket() click to toggle source
# File lib/execjs/fastnode/external_piped_runtime.rb, line 41
def socket
  UNIXSocket.new(@socket_path)
end