Class: Guard::Rubocop

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/rubocop.rb,
lib/guard/rubocop/runner.rb

Overview

This class gets API calls from ‘guard` and runs `rubocop` command via Runner. An instance of this class stays alive in a `guard` command session.

Defined Under Namespace

Classes: Runner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Rubocop

Returns a new instance of Rubocop.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/guard/rubocop.rb', line 14

def initialize(watchers = [], options = {})
  super

  @options = {
    all_on_start: true,
    keep_failed:  true,
    notification: :failed,
    cli: nil
  }.merge(options)

  @failed_paths = []
end

Instance Attribute Details

#failed_pathsObject (readonly)

Returns the value of attribute failed_paths.



12
13
14
# File 'lib/guard/rubocop.rb', line 12

def failed_paths
  @failed_paths
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/guard/rubocop.rb', line 12

def options
  @options
end

Instance Method Details

#clean_paths(paths) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/guard/rubocop.rb', line 50

def clean_paths(paths)
  paths = paths.dup
  paths.map! { |path| File.expand_path(path) }
  paths.uniq!
  paths.reject! do |path|
    included_in_other_path?(path, paths)
  end
  paths
end

#reloadObject



46
47
48
# File 'lib/guard/rubocop.rb', line 46

def reload
  @failed_paths = []
end

#run_allObject



31
32
33
34
# File 'lib/guard/rubocop.rb', line 31

def run_all
  UI.info 'Inspecting Ruby code style of all files'
  run
end

#run_on_changes(paths) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/guard/rubocop.rb', line 36

def run_on_changes(paths)
  paths += @failed_paths if @options[:keep_failed]
  paths = clean_paths(paths)

  displayed_paths = paths.map { |path| smart_path(path) }
  UI.info "Inspecting Ruby code style: #{displayed_paths.join(' ')}"

  run(paths)
end

#startObject



27
28
29
# File 'lib/guard/rubocop.rb', line 27

def start
  run_all if @options[:all_on_start]
end