Sha256: ed9cb3fa91c6594fc3a5eafa8ca3140128525519799ba638cc1a9fe1018a0459

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'shellwords'
require 'socket'

#
# This code is based on https://github.com/fohte/rubocop-daemon.
#
# Copyright (c) 2018 Hayato Kawai
#
# The MIT License (MIT)
#
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
#
module RuboCop
  module Server
    module ClientCommand
      # Abstract base class for server client command.
      # @api private
      class Base
        def run
          raise NotImplementedError
        end

        private

        def send_request(command:, args: [], body: '')
          TCPSocket.open('127.0.0.1', Cache.port_path.read) do |socket|
            socket.puts [Cache.token_path.read, Dir.pwd, command, *args].shelljoin
            socket.write body
            socket.close_write
            $stdout.write socket.read(4096) until socket.eof?
          end
        end

        def check_running_server
          Server.running?.tap do |running|
            warn 'RuboCop server is not running.' unless running
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/server/client_command/base.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/server/client_command/base.rb
rubocop-1.31.2 lib/rubocop/server/client_command/base.rb
rubocop-1.31.1 lib/rubocop/server/client_command/base.rb
rubocop-1.31.0 lib/rubocop/server/client_command/base.rb