Class: GoogleLintRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/google_lint/google_lint_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(binary, fix_style_binary, dir, filter, config) ⇒ GoogleLintRunner

Returns a new instance of GoogleLintRunner.



3
4
5
6
7
8
9
10
# File 'lib/tasks/google_lint/google_lint_runner.rb', line 3

def initialize(binary, fix_style_binary, dir, filter, config)
  @binary = binary
  @fix_style_binary = fix_style_binary
  @config_file = dir + '/gjslint.yml'
  @dir = dir
  @filter = filter
  @config = config
end

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tasks/google_lint/google_lint_runner.rb', line 16

def execute
  @config.reload
  conf = @config.conf

  input_params = ''
  run_fix_style = false

  conf.each do |param, value|

    if param == 'strict'
      input_params += " --#{param}"
      next
    end
    
    if param == 'run-fix-style'
      run_fix_style = true
      next
    end

    if value.kind_of? Array
      
      value.each do |inner_value|
        input_params += " --#{param} \"#{inner_value}\""
      end
      
    elsif value.kind_of? Integer
      input_params += " --#{param} #{value}"
    else
      input_params += " --#{param} \"#{value}\""
    end
  end

  result = ''
  result += `#{@fix_style_binary} #{input_params} . 2>&1` if run_fix_style

  return result + `#{@binary} #{input_params} . 2>&1`
end

#is_configured?(all_files) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/tasks/google_lint/google_lint_runner.rb', line 54

def is_configured?(all_files)
  return all_files.include?(@config_file)
end

#nameObject



12
13
14
# File 'lib/tasks/google_lint/google_lint_runner.rb', line 12

def name
  return 'Google Lint'
end

#should_run?(modified_files) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/tasks/google_lint/google_lint_runner.rb', line 58

def should_run?(modified_files)
  return !(modified_files.detect { |file| @filter.filter(file) }).nil? || modified_files.include?(@config_file)
end