Sha256: 4c3e46a462a4efd569b155aba0ddc1efe34b36ecee9f7baa790d842519f79859

Contents?: true

Size: 1.04 KB

Versions: 196

Compression:

Stored size: 1.04 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.readpartial(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

196 entries across 191 versions & 20 rubygems

Version Path
rubocop-1.74.0 lib/rubocop/server/client_command/base.rb
rubocop-1.73.2 lib/rubocop/server/client_command/base.rb
siteimprove_api_client-1.0.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.73.1/lib/rubocop/server/client_command/base.rb
rubocop-1.73.1 lib/rubocop/server/client_command/base.rb
rubocop-1.73.0 lib/rubocop/server/client_command/base.rb
rubocop-1.72.2 lib/rubocop/server/client_command/base.rb
rubocop-1.72.1 lib/rubocop/server/client_command/base.rb
rubocop-1.72.0 lib/rubocop/server/client_command/base.rb
rubocop-1.71.2 lib/rubocop/server/client_command/base.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-1.71.1/lib/rubocop/server/client_command/base.rb
rubocop-1.71.1 lib/rubocop/server/client_command/base.rb
rubocop-1.71.0 lib/rubocop/server/client_command/base.rb
rubocop-1.70.0 lib/rubocop/server/client_command/base.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/server/client_command/base.rb
rubocop-1.69.2 lib/rubocop/server/client_command/base.rb
rubocop-1.69.1 lib/rubocop/server/client_command/base.rb
rubocop-1.69.0 lib/rubocop/server/client_command/base.rb
rubocop-1.68.0 lib/rubocop/server/client_command/base.rb
rubocop-1.67.0 lib/rubocop/server/client_command/base.rb
rubocop-1.66.1 lib/rubocop/server/client_command/base.rb