Class: Guard::Rubocop
- 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
-
#failed_paths ⇒ Object
readonly
Returns the value of attribute failed_paths.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #clean_paths(paths) ⇒ Object
-
#initialize(watchers = [], options = {}) ⇒ Rubocop
constructor
A new instance of Rubocop.
- #reload ⇒ Object
- #run_all ⇒ Object
- #run_on_changes(paths) ⇒ Object
- #start ⇒ Object
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 = [], = {}) super @options = { all_on_start: true, keep_failed: true, notification: :failed, cli: nil }.merge() @failed_paths = [] end |
Instance Attribute Details
#failed_paths ⇒ Object (readonly)
Returns the value of attribute failed_paths.
12 13 14 |
# File 'lib/guard/rubocop.rb', line 12 def failed_paths @failed_paths end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/guard/rubocop.rb', line 12 def @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.(path) } paths.uniq! paths.reject! do |path| included_in_other_path?(path, paths) end paths end |
#reload ⇒ Object
46 47 48 |
# File 'lib/guard/rubocop.rb', line 46 def reload @failed_paths = [] end |
#run_all ⇒ Object
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 |
#start ⇒ Object
27 28 29 |
# File 'lib/guard/rubocop.rb', line 27 def start run_all if @options[:all_on_start] end |