Class: ASAutotest::ProblematicFile

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/asautotest/problematic-file.rb

Constant Summary

Constants included from Logging

Logging::PREFIX

Instance Method Summary collapse

Methods included from Logging

#barf, #end_saying, #end_whisper, #hint, #new_logging_section, #say, #say_with_block, #say_without_block, #shout, #start_saying, #start_whisper, verbose=, verbose?, #verbose?, #whisper, #whisper_with_block, #whisper_without_block

Constructor Details

#initialize(file_name, source_directories) ⇒ ProblematicFile

Returns a new instance of ProblematicFile.



24
25
26
27
28
# File 'lib/asautotest/problematic-file.rb', line 24

def initialize(file_name, source_directories)
  @file_name = file_name
  @source_directories = source_directories
  @problems = []
end

Instance Method Details

#<<(problem) ⇒ Object



30
31
32
33
34
# File 'lib/asautotest/problematic-file.rb', line 30

def << problem
  @problems << problem
  problem.file = self
  @problems = @problems.sort_by { |x| x.sort_key }
end

#any_type_warnings?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/asautotest/problematic-file.rb', line 44

def any_type_warnings?
  @problems.any? &:type_warning?
end

#basenameObject



74
75
76
77
78
79
80
# File 'lib/asautotest/problematic-file.rb', line 74

def basename
  if @file_name == nil
    "(compiler error)"
  else
    File.basename(@file_name)
  end
end

#dirnameObject



82
83
84
# File 'lib/asautotest/problematic-file.rb', line 82

def dirname
  File.dirname(stripped_file_name) if has_file_name?
end

#has_file_name?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/asautotest/problematic-file.rb', line 70

def has_file_name?
  @file_name != nil
end

#n_problemsObject



36
37
38
# File 'lib/asautotest/problematic-file.rb', line 36

def n_problems
  @problems.size
end


61
62
63
64
65
66
67
68
# File 'lib/asautotest/problematic-file.rb', line 61

def print_report
  puts
  print ljust("\e[1m#{basename}\e[0m", 40)
  print "  (in #{dirname})" unless dirname == "." if has_file_name?
  puts

  @problems.each &:print_report
end

#problem_before(next_problem) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/asautotest/problematic-file.rb', line 48

def problem_before(next_problem)
  returning nil do
    previous_problem = nil
    for problem in @problems do
      if problem == next_problem
        return previous_problem
      else
        previous_problem = problem
      end
    end
  end
end

#source_directoryObject



94
95
96
97
98
# File 'lib/asautotest/problematic-file.rb', line 94

def source_directory
  @source_directories.find do |directory|
    @file_name.start_with? directory
  end
end

#stripped_file_nameObject



86
87
88
89
90
91
92
# File 'lib/asautotest/problematic-file.rb', line 86

def stripped_file_name
  if source_directory
    @file_name[source_directory.size .. -1]
  else
    @file_name
  end
end

#typeObject



40
41
42
# File 'lib/asautotest/problematic-file.rb', line 40

def type
  Type[dirname.gsub(/\/|\\/, "."), basename.sub(/\..*$/, "")]
end