Sha256: 10afa85922c70e6baf8b414589cbbfac84941cf57ecc0ddf03d0b6a2b49447e8

Contents?: true

Size: 1.55 KB

Versions: 15

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

#
# 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
      # This class is a client command to execute server process.
      # @api private
      class Exec < Base
        def run
          ensure_server!
          read_stdin = ARGV.include?('-s') || ARGV.include?('--stdin')
          send_request(
            command: 'exec',
            args: ARGV.dup,
            body: read_stdin ? $stdin.read : ''
          )
          warn stderr unless stderr.empty?
          status
        end

        private

        def ensure_server!
          if incompatible_version?
            warn 'RuboCop version incompatibility found, RuboCop server restarting...'
            ClientCommand::Stop.new.run
          elsif check_running_server
            return
          end

          ClientCommand::Start.new.run
        end

        def incompatible_version?
          Cache.version_path.read != RuboCop::Version::STRING
        end

        def stderr
          Cache.stderr_path.read
        end

        def status
          unless Cache.status_path.file?
            raise "RuboCop server: Could not find status file at: #{Cache.status_path}"
          end

          status = Cache.status_path.read
          raise "RuboCop server: '#{status}' is not a valid status!" if (status =~ /^\d+$/).nil?

          status.to_i
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/server/client_command/exec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/server/client_command/exec.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/client_command/exec.rb
rubocop-1.64.1 lib/rubocop/server/client_command/exec.rb
rubocop-1.63.4 lib/rubocop/server/client_command/exec.rb
rubocop-1.63.3 lib/rubocop/server/client_command/exec.rb
rubocop-1.63.2 lib/rubocop/server/client_command/exec.rb
rubocop-1.63.1 lib/rubocop/server/client_command/exec.rb
rubocop-1.63.0 lib/rubocop/server/client_command/exec.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/server/client_command/exec.rb
rubocop-1.62.1 lib/rubocop/server/client_command/exec.rb
rubocop-1.62.0 lib/rubocop/server/client_command/exec.rb
rubocop-1.61.0 lib/rubocop/server/client_command/exec.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/server/client_command/exec.rb
rubocop-1.60.2 lib/rubocop/server/client_command/exec.rb