Class: Renegade::Linters
- Inherits:
-
Object
- Object
- Renegade::Linters
- Defined in:
- lib/renegade/linters.rb
Overview
Run linters
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#append_file_count(files) ⇒ Object
Add the file count to the end of the label.
- #exec(files) ⇒ Object
- #filter_files(file_list) ⇒ Object
-
#initialize(label, extension, exec_command) ⇒ Linters
constructor
A new instance of Linters.
- #run(files) ⇒ Object
Constructor Details
#initialize(label, extension, exec_command) ⇒ Linters
Returns a new instance of Linters.
9 10 11 12 13 14 15 |
# File 'lib/renegade/linters.rb', line 9 def initialize(label, extension, exec_command) # Instance variables @label = label @extension = extension @exec_command = exec_command @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/renegade/linters.rb', line 7 def errors @errors end |
Instance Method Details
#append_file_count(files) ⇒ Object
Add the file count to the end of the label
30 31 32 33 34 35 36 37 |
# File 'lib/renegade/linters.rb', line 30 def append_file_count(files) file_size = files.size label_count = (file_size == 0 || file_size > 1) ? "#{file_size} files" : '1 file' @label = "#{@label} (#{label_count})" end |
#exec(files) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/renegade/linters.rb', line 39 def exec(files) # http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby stdin, stdout, stderr, wait_thread = Open3.popen3(@exec_command + " #{files.join(' ')}") @errors.push(stdout.read) if wait_thread.value.exitstatus == 1 stdin.close stdout.close stderr.close wait_thread.value.exitstatus == 0 end |
#filter_files(file_list) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/renegade/linters.rb', line 53 def filter_files(file_list) filtered_files = [] file_list.each do |file| filtered_files.push(file) if File.extname(file) == @extension end filtered_files end |
#run(files) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/renegade/linters.rb', line 17 def run(files) files = filter_files(files) append_file_count(files) # Only run check if there are relevant files being committed if files.empty? Status.report(@label, true) else Status.report(@label, exec(files)) end end |