Class: Tailor::Critic
- Inherits:
-
Object
- Object
- Tailor::Critic
- Includes:
- Logger::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
Methods included from Logger::Mixin
Instance Method Details
#check_file(file, style) ⇒ Hash
Adds problems found from Lexing to the #problems
list.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tailor/critic.rb', line 62 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.
50 51 52 53 54 55 56 |
# File 'lib/tailor/critic.rb', line 50 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
45 46 47 |
# File 'lib/tailor/critic.rb', line 45 def problems @problems ||= {} end |