Class: Tailor::Critic
- Inherits:
-
Object
- Object
- Tailor::Critic
- Includes:
- LogSwitch::Mixin, Rulers
- Defined in:
- lib/tailor/critic.rb
Overview
An object of this type provides for starting the process of critiquing files. It handles initializing the Ruler objects it needs based on the configuration given to it.
Instance Method Summary collapse
-
#check_file(file, style) ⇒ Hash
Adds problems found from Lexing to the
#problems
list. -
#critique(file_sets) {|problems, label| ... } ⇒ Object
The instance method that starts the process of looking for problems in files.
-
#problem_count(type = nil) ⇒ Fixnum
The number of problems found so far.
-
#problems ⇒ Hash{String => Array}
The list of problems, where the keys are the file names in which the problems were found, and the values are the respective lists of problems for each file.
Instance Method Details
#check_file(file, style) ⇒ Hash
Adds problems found from Lexing to the #problems
list.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tailor/critic.rb', line 64 def check_file(file, style) log "<#{self.class}> Checking style of file: #{file}." lexer = Tailor::Lexer.new(file) ruler = Ruler.new log 'Style:' style.each { |property, values| log "#{property}: #{values}" } init_rulers(style, lexer, ruler) lexer.lex problems[file] = ruler.problems { file => problems[file] } end |
#critique(file_sets) {|problems, label| ... } ⇒ Object
The instance method that starts the process of looking for problems in files. It checks for problems in each file in each file set. It yields the problems found and the label they were found for.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tailor/critic.rb', line 23 def critique(file_sets) log "file sets keys: #{file_sets.keys}" file_sets.each do |label, file_set| log "Critiquing file_set: #{file_set}" file_set[:file_list].each do |file| log "Critiquing file: #{file}" begin problems = check_file(file, file_set[:style]) rescue => ex $stderr.puts "Error while parsing file #{file}" raise(ex) end yield [problems, label] if block_given? end end end |
#problem_count(type = nil) ⇒ Fixnum
Returns The number of problems found so far.
52 53 54 55 56 57 58 |
# File 'lib/tailor/critic.rb', line 52 def problem_count(type=nil) if type.nil? problems.values.flatten.size else problems.values.flatten.find_all { |v| v[:level] == :error }.size end end |
#problems ⇒ Hash{String => Array}
Returns The list of problems, where the keys are the file names in which the problems were found, and the values are the respective lists of problems for each file.
47 48 49 |
# File 'lib/tailor/critic.rb', line 47 def problems @problems ||= {} end |