Sha256: b7e3ba3f848b3d0914cee9f6cfe7ff90e031e436c9c1c618aabb703414831fd8

Contents?: true

Size: 1.44 KB

Versions: 19

Compression:

Stored size: 1.44 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!
          Cache.status_path.delete if Cache.status_path.file?
          send_request(
            command: 'exec',
            args: ARGV.dup,
            body: $stdin.tty? ? '' : $stdin.read
          )
          status
        end

        private

        def ensure_server!
          if incompatible_version?
            puts '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?
          RuboCop::Version::STRING != Cache.version_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

19 entries across 15 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/server/client_command/exec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/server/client_command/exec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/server/client_command/exec.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/server/client_command/exec.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/server/client_command/exec.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/server/client_command/exec.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/server/client_command/exec.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/server/client_command/exec.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/server/client_command/exec.rb
rubocop-1.36.0 lib/rubocop/server/client_command/exec.rb
rubocop-1.35.1 lib/rubocop/server/client_command/exec.rb
rubocop-1.35.0 lib/rubocop/server/client_command/exec.rb
rubocop-1.34.1 lib/rubocop/server/client_command/exec.rb
rubocop-1.34.0 lib/rubocop/server/client_command/exec.rb
rubocop-1.33.0 lib/rubocop/server/client_command/exec.rb
rubocop-1.32.0 lib/rubocop/server/client_command/exec.rb
rubocop-1.31.2 lib/rubocop/server/client_command/exec.rb
rubocop-1.31.1 lib/rubocop/server/client_command/exec.rb
rubocop-1.31.0 lib/rubocop/server/client_command/exec.rb