rubocop-daemon 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +4 -6
- data/lib/rubocop/daemon.rb +1 -1
- data/lib/rubocop/daemon/cache.rb +8 -2
- data/lib/rubocop/daemon/cli.rb +1 -0
- data/lib/rubocop/daemon/client_command/start.rb +2 -1
- data/lib/rubocop/daemon/server.rb +14 -6
- data/lib/rubocop/daemon/socket_reader.rb +3 -1
- data/lib/rubocop/daemon/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b7fc85bc8f0d4eec8c3e059c0dfd63131165881e99b9df8f675569cc9f482d5
|
4
|
+
data.tar.gz: 8ac1b60ad89d68fd52b9bae1ce5d5f9f2579307e4f68934726077efb4669fa1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ee5f72d514f94b91b5ddddee5a68db28627367e09639e017b80a73500b0343c78f6d4ebee344ed17f88ce3a99558b17b232f75cf8d45541bd733b46db9dc0d8
|
7
|
+
data.tar.gz: cabc9bca1782ec0b20425b76ca4494e7b887135b0b8f50729044055d7795ba4698a3f355c9ca89fb62b33e931b01c07187198d0dabbf74c310741603a9113df1
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
# rubocop-daemon
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem](https://img.shields.io/gem/v/rubocop-daemon.svg)](https://rubygems.org/gems/rubocop-daemon)
|
4
4
|
|
5
|
-
|
5
|
+
`rubocop-daemon` makes RuboCop faster.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
`rubocop-daemon`
|
9
|
+
Install `rubocop-daemon` via rubygems.org:
|
10
10
|
|
11
11
|
```sh
|
12
|
-
|
13
|
-
bundle install
|
14
|
-
bundle exec rake install
|
12
|
+
gem install rubocop-daemon
|
15
13
|
```
|
16
14
|
|
17
15
|
## Usage
|
data/lib/rubocop/daemon.rb
CHANGED
data/lib/rubocop/daemon/cache.rb
CHANGED
@@ -6,8 +6,8 @@ module RuboCop
|
|
6
6
|
module Daemon
|
7
7
|
class Cache
|
8
8
|
def self.dir
|
9
|
-
Pathname.new(File.expand_path('~/.cache/rubocop-daemon')).tap do |d|
|
10
|
-
d.
|
9
|
+
Pathname.new(File.join(File.expand_path('~/.cache/rubocop-daemon'), Dir.pwd[1..-1].tr('/', '+'))).tap do |d|
|
10
|
+
d.mkpath unless d.exist?
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -23,6 +23,12 @@ module RuboCop
|
|
23
23
|
dir.join('pid')
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.pid_running?
|
27
|
+
Process.kill 0, pid_path.read.to_i
|
28
|
+
rescue Errno::ESRCH
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
26
32
|
def self.make_server_file(port:, token:)
|
27
33
|
port_path.write(port)
|
28
34
|
token_path.write(token)
|
data/lib/rubocop/daemon/cli.rb
CHANGED
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
class Start < Base
|
7
7
|
def run
|
8
8
|
parser.parse(@argv)
|
9
|
-
Server.new.start(@options.fetch(:port, 0))
|
9
|
+
Server.new(@options.fetch(:no_daemon, false)).start(@options.fetch(:port, 0))
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
@@ -16,6 +16,7 @@ module RuboCop
|
|
16
16
|
p.banner = 'usage: rubocop-daemon start [options]'
|
17
17
|
|
18
18
|
p.on('-p', '--port [PORT]') { |v| @options[:port] = v }
|
19
|
+
p.on('--no-daemon', 'Starts server in foreground with debug information') { @options[:no_daemon] = true }
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -7,12 +7,14 @@ require 'securerandom'
|
|
7
7
|
module RuboCop
|
8
8
|
module Daemon
|
9
9
|
class Server
|
10
|
+
attr_reader :verbose
|
11
|
+
|
10
12
|
def self.token
|
11
13
|
@token ||= SecureRandom.hex(4)
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
|
16
|
+
def initialize(verbose)
|
17
|
+
@verbose = verbose
|
16
18
|
end
|
17
19
|
|
18
20
|
def token
|
@@ -21,24 +23,30 @@ module RuboCop
|
|
21
23
|
|
22
24
|
def start(port)
|
23
25
|
require 'rubocop'
|
24
|
-
|
25
|
-
|
26
|
+
start_server(port)
|
27
|
+
Process.daemon(true) unless verbose
|
26
28
|
Cache.make_server_file(port: @server.addr[1], token: token) do
|
27
|
-
Process.daemon(true)
|
28
29
|
read_socket(@server.accept) until @server.closed?
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
33
34
|
|
35
|
+
def start_server(port)
|
36
|
+
@server = TCPServer.open('127.0.0.1', port)
|
37
|
+
puts "Server listen on port #{@server.addr[1]}" if verbose
|
38
|
+
end
|
39
|
+
|
34
40
|
def read_socket(socket)
|
35
|
-
SocketReader.new(socket).read!
|
41
|
+
SocketReader.new(socket, verbose).read!
|
36
42
|
rescue InvalidTokenError
|
37
43
|
socket.puts 'token is not valid.'
|
38
44
|
rescue ServerStopRequest
|
39
45
|
@server.close
|
40
46
|
rescue UnknownServerCommandError => e
|
41
47
|
socket.puts e.message
|
48
|
+
rescue Errno::EPIPE => e
|
49
|
+
p e if verbose
|
42
50
|
rescue StandardError => e
|
43
51
|
socket.puts e.full_message
|
44
52
|
ensure
|
@@ -6,8 +6,9 @@ module RuboCop
|
|
6
6
|
Request = Struct.new(:header, :body)
|
7
7
|
Header = Struct.new(:token, :cwd, :command, :args)
|
8
8
|
|
9
|
-
def initialize(socket)
|
9
|
+
def initialize(socket, verbose)
|
10
10
|
@socket = socket
|
11
|
+
@verbose = verbose
|
11
12
|
end
|
12
13
|
|
13
14
|
def read!
|
@@ -25,6 +26,7 @@ module RuboCop
|
|
25
26
|
private
|
26
27
|
|
27
28
|
def parse_request(content)
|
29
|
+
puts content if @verbose
|
28
30
|
raw_header, *body = content.lines
|
29
31
|
Request.new(parse_header(raw_header), body.join)
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hayato Kawai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.7.
|
128
|
+
rubygems_version: 2.7.6
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Makes RuboCop faster
|