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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5579693de992c601188ad58c5ea7e3e5988ac40e6b3d2344000e454ae48f566
4
- data.tar.gz: b2e0ffca2fa243fe6bfc687b1710871317f9e358850ea4ebe7c42903f885372b
3
+ metadata.gz: 5b7fc85bc8f0d4eec8c3e059c0dfd63131165881e99b9df8f675569cc9f482d5
4
+ data.tar.gz: 8ac1b60ad89d68fd52b9bae1ce5d5f9f2579307e4f68934726077efb4669fa1f
5
5
  SHA512:
6
- metadata.gz: a992d260d61f322ce081554e10e64330cc01e3ec868134da73a8c2c5fa79f472470b4de54b122399cd5db7812d37f2ee4c0b5b6be6d86e260f42b5366b15e5de
7
- data.tar.gz: 555be81d6ae5c2a6b8b0e0b465caaffdb227faa769e9214165d1d616799d81f17ec1993aca274475179bb1f177622728254da219ccb820c9ee28662e8402d092
6
+ metadata.gz: 4ee5f72d514f94b91b5ddddee5a68db28627367e09639e017b80a73500b0343c78f6d4ebee344ed17f88ce3a99558b17b232f75cf8d45541bd733b46db9dc0d8
7
+ data.tar.gz: cabc9bca1782ec0b20425b76ca4494e7b887135b0b8f50729044055d7795ba4698a3f355c9ca89fb62b33e931b01c07187198d0dabbf74c310741603a9113df1
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.1
2
+ TargetRubyVersion: 2.2
3
3
 
4
4
  Style/FrozenStringLiteralComment:
5
5
  EnforcedStyle: always
data/README.md CHANGED
@@ -1,17 +1,15 @@
1
1
  # rubocop-daemon
2
2
 
3
- `rubocop-daemon` makes RuboCop faster.
3
+ [![Gem](https://img.shields.io/gem/v/rubocop-daemon.svg)](https://rubygems.org/gems/rubocop-daemon)
4
4
 
5
- **This tool is beta version.**
5
+ `rubocop-daemon` makes RuboCop faster.
6
6
 
7
7
  ## Installation
8
8
 
9
- `rubocop-daemon` is not released on rubygems.org yet, but you can try `rubocop-daemon`:
9
+ Install `rubocop-daemon` via rubygems.org:
10
10
 
11
11
  ```sh
12
- git clone https://github.com/fohte/rubocop-daemon.git && cd rubocop-daemon
13
- bundle install
14
- bundle exec rake install
12
+ gem install rubocop-daemon
15
13
  ```
16
14
 
17
15
  ## Usage
@@ -13,7 +13,7 @@ module RuboCop
13
13
  autoload :SocketReader, 'rubocop/daemon/socket_reader'
14
14
 
15
15
  def self.running?
16
- Cache.dir.exist?
16
+ Cache.dir.exist? && Cache.pid_path.file? && Cache.pid_running?
17
17
  end
18
18
  end
19
19
  end
@@ -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.mkdir unless d.exist?
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)
@@ -15,6 +15,7 @@ module RuboCop
15
15
  def run(argv = ARGV)
16
16
  parser.order!(argv)
17
17
  return if argv.empty?
18
+
18
19
  create_subcommand_instance(argv)
19
20
  rescue OptionParser::InvalidOption => e
20
21
  warn "error: #{e.message}"
@@ -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 self.start(port)
15
- new.start(port)
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
- @server = TCPServer.open('127.0.0.1', port)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Daemon
5
- VERSION = '0.1.0'.freeze
5
+ VERSION = '0.2.0'.freeze
6
6
  end
7
7
  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.1.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-04-04 00:00:00.000000000 Z
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.3
128
+ rubygems_version: 2.7.6
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Makes RuboCop faster