Class: CI::Syntax::Tool::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/ci-syntax-tool/checker.rb

Overview

CI::Syntax::Tool::Checker

Main driver of the tool.  For each language,
locates files, runs the check, and outputs
to each formatter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd_line) ⇒ Checker

Returns a new instance of Checker.



12
13
14
# File 'lib/ci-syntax-tool/checker.rb', line 12

def initialize(cmd_line)
  @cmd_line = cmd_line
end

Instance Attribute Details

#cmd_lineObject (readonly)

Returns the value of attribute cmd_line.



9
10
11
# File 'lib/ci-syntax-tool/checker.rb', line 9

def cmd_line
  @cmd_line
end

#overall_resultObject (readonly)

Returns the value of attribute overall_result.



10
11
12
# File 'lib/ci-syntax-tool/checker.rb', line 10

def overall_result
  @overall_result
end

Instance Method Details

#runObject



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
53
54
55
56
57
58
59
60
61
# File 'lib/ci-syntax-tool/checker.rb', line 16

def run
  unless cmd_line.runnable?
    return cmd_line.non_runnable_exit_status
  end
  
  formats = []
  cmd_line.options[:formats].each_with_index do |fmt_name, idx|
    formats << FormatFactory.create(fmt_name, cmd_line.options[:outputs][idx])
  end
  
  @overall_result = Result::OverallResult.new()
  formats.each { |fmt| fmt.overall_started(overall_result) }
  
  cmd_line.options[:languages].each do |lang_name|
    language_result = overall_result.add_language_result(lang_name)
    lang = LanguageFactory.create(lang_name)
    
    lang.check_starting(language_result)
    formats.each { |fmt| fmt.lang_started(language_result) }
    
    cmd_line.file_args.each do |argpath|
      if FileTest.directory?(argpath)
        Dir.chdir(argpath) do                  
          Dir.glob(lang.combined_globs).each do |path|
            file_result = language_result.add_file_result(path)
            formats.each { |fmt| fmt.file_started(file_result) }
            lang.check_file(file_result)
            formats.each { |fmt| fmt.file_finished(file_result) }
          end
        end
      else
        # No glob check here - user explicitly specified a file
        file_result = language_result.add_file_result(argpath)
        formats.each { |fmt| fmt.file_started(file_result) }
        lang.check_file(file_result)
        formats.each { |fmt| fmt.file_finished(file_result) }
      end
    end
    lang.check_ending(language_result)
    formats.each { |fmt| fmt.lang_finished(language_result) }
  end

  formats.each { |fmt| fmt.overall_finished(overall_result) }
  return overall_result.report_failure? ? 1 : 0
  
end