123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Server::SocketReader Private

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: lib/rubocop/server/socket_reader.rb

Overview

This class sends the request read from the socket to server.

Class Method Summary

Instance Method Summary

Instance Method Details

#create_command_instance(request) (private)

[ GitHub ]

  
# File 'lib/rubocop/server/socket_reader.rb', line 53

def create_command_instance(request)
  klass = find_command_class(request.header.command)

  klass.new(request.header.args, token: request.header.token, cwd: request.header.cwd)
end

#find_command_class(command) (private)

[ GitHub ]

  
# File 'lib/rubocop/server/socket_reader.rb', line 59

def find_command_class(command)
  case command
  when 'stop' then ServerCommand::Stop
  when 'exec' then ServerCommand::Exec
  else
    raise UnknownServerCommandError, "#{command.inspect} is not a valid command"
  end
end

#parse_header(header) (private)

[ GitHub ]

  
# File 'lib/rubocop/server/socket_reader.rb', line 48

def parse_header(header)
  token, cwd, command, *args = header.shellsplit
  Header.new(token, cwd, command, args)
end

#parse_request(content) (private)

[ GitHub ]

  
# File 'lib/rubocop/server/socket_reader.rb', line 42

def parse_request(content)
  raw_header, *body = content.lines

  Request.new(parse_header(raw_header), body.join)
end

#read!

[ GitHub ]

  
# File 'lib/rubocop/server/socket_reader.rb', line 24

def read!
  request = parse_request(@socket.read)

  stderr = StringIO.new
  Helper.redirect(
    stdin: StringIO.new(request.body),
    stdout: @socket,
    stderr: stderr
  ) do
    create_command_instance(request).run
  end
ensure
  Cache.stderr_path.write(stderr.string)
  @socket.close
end