Class: FoodCritic::Review

Inherits:
Object
  • Object
show all
Defined in:
lib/foodcritic/domain.rb

Overview

The collected warnings (if any) raised against a cookbook tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookbook_paths, warnings) ⇒ Review

Returns a new instance of Review.



44
45
46
47
# File 'lib/foodcritic/domain.rb', line 44

def initialize(cookbook_paths, warnings)
  @cookbook_paths = Array(cookbook_paths)
  @warnings = warnings
end

Instance Attribute Details

#cookbook_pathsObject (readonly)

Returns the value of attribute cookbook_paths.



42
43
44
# File 'lib/foodcritic/domain.rb', line 42

def cookbook_paths
  @cookbook_paths
end

#warningsObject (readonly)

Returns the value of attribute warnings.



42
43
44
# File 'lib/foodcritic/domain.rb', line 42

def warnings
  @warnings
end

Instance Method Details

#failed?Boolean

If any of the warnings in this review have failed or not.

Returns:

  • (Boolean)


50
51
52
# File 'lib/foodcritic/domain.rb', line 50

def failed?
  warnings.any?(&:failed?)
end

#failuresObject

Returns an array of warnings that are marked as failed.



55
56
57
# File 'lib/foodcritic/domain.rb', line 55

def failures
  warnings.select(&:failed?)
end

#to_sObject

Returns a string representation of this review. This representation is liable to change.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/foodcritic/domain.rb', line 61

def to_s
  # Sorted by filename and line number.
  #
  #     FC123: My rule name: foo/recipes/default.rb
  @warnings.map do |w|
    ["#{w.rule.code}: #{w.rule.name}: #{w.match[:filename]}",
     w.match[:line].to_i]
  end.sort do |x, y|
    x.first == y.first ? x[1] <=> y[1] : x.first <=> y.first
  end.map { |w| "#{w.first}:#{w[1]}" }.uniq.join("\n")
end