gry 0.4.0 → 0.5.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
  SHA1:
3
- metadata.gz: b42e23132942ef6df96fec3c692ff47835f16c81
4
- data.tar.gz: b25bd4caf24782e145033074c4de66331338a8be
3
+ metadata.gz: 61403908364d6b8a076ca3b158db740638fd99e6
4
+ data.tar.gz: 9f8a3b348cb9990fd1cf20994f4aa115a78ebbd2
5
5
  SHA512:
6
- metadata.gz: f1a633e62726375d702a804e32a3f2a8cf3fe903199f742ec8317e424a5a1699a8dde67cca8c85825d0e6489401a69ccd93992291698fb11c1316efc88e785bd
7
- data.tar.gz: d8b06696c150d83cebe3419f14bd7a25d3d697941507bb3f7d4203c7874b7b2ef665ed6101a9c1220a27a0185c3d000a5ea39366c3837d3fc570380b924aeb84
6
+ metadata.gz: 67ae839eb8b9fdf577a41e7ee82060c4b87c251bb95e9ff939ee270179ecd5ee262a06624299fc36d549e625deabf0dd4846668a25fcfe48fae43eb6e44c81fc
7
+ data.tar.gz: 0b898367f552894f237520ad88432628f77ada36703024b19073f45e12df553fed9dadd7d502aa2ed240347d62e3aeb4ec7cff736530895234b101c8e6fdbea7
data/.travis.yml CHANGED
@@ -8,3 +8,8 @@ gemfile:
8
8
  - gemfiles/rubocop_0.48.1.gemfile
9
9
  - gemfiles/rubocop_0.47.1.gemfile
10
10
  - gemfiles/rubocop_head.gemfile
11
+ matrix:
12
+ include:
13
+ allow_failures:
14
+ - gemfile: gemfiles/rubocop_head.gemfile
15
+ fast_finish: true
data/lib/gry.rb CHANGED
@@ -4,6 +4,7 @@ require 'yaml'
4
4
  require 'json'
5
5
  require 'optparse'
6
6
  require 'open3'
7
+ require 'pathname'
7
8
 
8
9
  require 'rubocop'
9
10
  require 'parallel'
data/lib/gry/cli.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Gry
2
2
  class CLI
3
+ CACHE_PATH = Pathname(ENV['XDG_CACHE_HOME'] || '~/.cache').expand_path / 'gry/cache'
4
+
3
5
  def initialize(argv)
4
6
  @argv = argv
5
7
  end
@@ -16,9 +18,14 @@ module Gry
16
18
  if opt.fast
17
19
  cops.reject!{|cop| cop == 'Style/AlignHash'}
18
20
  end
19
- pilot_study = Gry::PilotStudy.new(cops, process: opt.process)
20
21
 
21
- bills = pilot_study.analyze
22
+ bills = (opt.cache && restore_cache(cops)) || begin
23
+ pilot_study = Gry::PilotStudy.new(cops, process: opt.process)
24
+ pilot_study.analyze.tap do |b|
25
+ save_cache(b, cops)
26
+ end
27
+ end
28
+
22
29
  congress = Congress.new(
23
30
  max_count: opt.max_count,
24
31
  min_difference: opt.min_difference,
@@ -31,5 +38,29 @@ module Gry
31
38
  fmt = Formatter.new(display_disabled_cops: opt.display_disabled_cops)
32
39
  writer.puts fmt.format(laws)
33
40
  end
41
+
42
+ def save_cache(bills, cops)
43
+ cache_dir = CACHE_PATH.dirname
44
+ Dir.mkdir(cache_dir) unless cache_dir.exist?
45
+ cache = {
46
+ bills: bills,
47
+ cops: cops,
48
+ created_at: Time.now,
49
+ }
50
+ File.write(CACHE_PATH, Marshal.dump(cache))
51
+ end
52
+
53
+ def restore_cache(cops)
54
+ return unless CACHE_PATH.exist?
55
+ cache = Marshal.load(File.read(CACHE_PATH))
56
+
57
+ return unless cops == cache[:cops]
58
+
59
+ cached_time = cache[:created_at]
60
+ not_changed = RubocopAdapter.find_target_files.map(&:chomp).all?{|file| File.ctime(file) < cached_time}
61
+ return unless not_changed
62
+
63
+ return cache[:bills]
64
+ end
34
65
  end
35
66
  end
data/lib/gry/option.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Gry
2
2
  class Option
3
- attr_reader :args, :process, :version, :fast, :max_count, :min_difference, :display_disabled_cops, :metrics_percentile
3
+ attr_reader :args, :process, :version, :fast, :max_count, :min_difference, :display_disabled_cops, :metrics_percentile, :cache
4
4
 
5
5
  def initialize(argv)
6
6
  opt = OptionParser.new
@@ -11,6 +11,7 @@ module Gry
11
11
  @min_difference = 10
12
12
  @display_disabled_cops = false
13
13
  @metrics_percentile = 95
14
+ @cache = true
14
15
 
15
16
  opt.banner = 'Usage: gry [options] [Cop1, Cop2, ...]'
16
17
 
@@ -22,6 +23,7 @@ module Gry
22
23
  opt.on('--min-difference=10', 'Lower limit of issues number difference') {|v| @min_difference = v.to_i}
23
24
  opt.on('--metrics-percentile=95', 'Percentile for allowed complex code') {|v| @metrics_percentile = v.to_i}
24
25
  opt.on('--display-disabled-cops', 'Display disabled cops') {|v| @display_disabled_cops = v}
26
+ opt.on('--[no-]cache', 'Run gry with cache. Default: true') {|v| @cache = v}
25
27
 
26
28
  @args = opt.parse(argv)
27
29
  end
@@ -74,5 +74,9 @@ module Gry
74
74
  }
75
75
  })
76
76
  end
77
+
78
+ def find_target_files
79
+ `rubocop --list-target-files`.each_line
80
+ end
77
81
  end
78
82
  end
data/lib/gry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gry
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Kuwabara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-09 00:00:00.000000000 Z
11
+ date: 2017-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler