Class: GemXray::Result
- Inherits:
-
Object
- Object
- GemXray::Result
- Defined in:
- lib/gemxray/result.rb
Defined Under Namespace
Classes: Reason
Constant Summary collapse
- SEVERITIES =
{ danger: 0, warning: 1, info: 2 }.freeze
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#gemfile_end_line ⇒ Object
readonly
Returns the value of attribute gemfile_end_line.
-
#gemfile_group ⇒ Object
readonly
Returns the value of attribute gemfile_group.
-
#gemfile_line ⇒ Object
readonly
Returns the value of attribute gemfile_line.
-
#reasons ⇒ Object
readonly
Returns the value of attribute reasons.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#suggestion ⇒ Object
readonly
Returns the value of attribute suggestion.
Instance Method Summary collapse
- #add_reason(type:, detail:, severity:) ⇒ Object
- #danger? ⇒ Boolean
- #info? ⇒ Boolean
-
#initialize(gem_name:, gemfile_line: nil, gemfile_end_line: nil, gemfile_group: nil, suggestion: nil, reasons: [], severity: nil) ⇒ Result
constructor
A new instance of Result.
- #merge!(other) ⇒ Object
- #reason_types ⇒ Object
- #severity_order ⇒ Object
- #to_h ⇒ Object
- #type_label ⇒ Object
Constructor Details
#initialize(gem_name:, gemfile_line: nil, gemfile_end_line: nil, gemfile_group: nil, suggestion: nil, reasons: [], severity: nil) ⇒ Result
Returns a new instance of Result.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gemxray/result.rb', line 16 def initialize(gem_name:, gemfile_line: nil, gemfile_end_line: nil, gemfile_group: nil, suggestion: nil, reasons: [], severity: nil) @gem_name = gem_name @gemfile_line = gemfile_line @gemfile_end_line = gemfile_end_line || gemfile_line @gemfile_group = gemfile_group @suggestion = suggestion || "Consider removing this entry from Gemfile" @reasons = reasons.dup @severity = severity || infer_severity end |
Instance Attribute Details
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
13 14 15 |
# File 'lib/gemxray/result.rb', line 13 def gem_name @gem_name end |
#gemfile_end_line ⇒ Object
Returns the value of attribute gemfile_end_line.
13 14 15 |
# File 'lib/gemxray/result.rb', line 13 def gemfile_end_line @gemfile_end_line end |
#gemfile_group ⇒ Object
Returns the value of attribute gemfile_group.
13 14 15 |
# File 'lib/gemxray/result.rb', line 13 def gemfile_group @gemfile_group end |
#gemfile_line ⇒ Object
Returns the value of attribute gemfile_line.
13 14 15 |
# File 'lib/gemxray/result.rb', line 13 def gemfile_line @gemfile_line end |
#reasons ⇒ Object (readonly)
Returns the value of attribute reasons.
13 14 15 |
# File 'lib/gemxray/result.rb', line 13 def reasons @reasons end |
#severity ⇒ Object
Returns the value of attribute severity.
14 15 16 |
# File 'lib/gemxray/result.rb', line 14 def severity @severity end |
#suggestion ⇒ Object
Returns the value of attribute suggestion.
13 14 15 |
# File 'lib/gemxray/result.rb', line 13 def suggestion @suggestion end |
Instance Method Details
#add_reason(type:, detail:, severity:) ⇒ Object
27 28 29 30 31 |
# File 'lib/gemxray/result.rb', line 27 def add_reason(type:, detail:, severity:) reasons << Reason.new(type: type.to_sym, detail: detail, severity: severity.to_sym) self.severity = infer_severity self end |
#danger? ⇒ Boolean
56 57 58 |
# File 'lib/gemxray/result.rb', line 56 def danger? severity == :danger end |
#info? ⇒ Boolean
60 61 62 |
# File 'lib/gemxray/result.rb', line 60 def info? severity == :info end |
#merge!(other) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gemxray/result.rb', line 33 def merge!(other) other.reasons.each do |reason| add_reason(type: reason.type, detail: reason.detail, severity: reason.severity) end self.gemfile_line ||= other.gemfile_line self.gemfile_end_line ||= other.gemfile_end_line self.gemfile_group ||= other.gemfile_group self.suggestion ||= other.suggestion self end |
#reason_types ⇒ Object
48 49 50 |
# File 'lib/gemxray/result.rb', line 48 def reason_types reasons.map(&:type).uniq end |
#severity_order ⇒ Object
44 45 46 |
# File 'lib/gemxray/result.rb', line 44 def severity_order SEVERITIES.fetch(severity) end |
#to_h ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gemxray/result.rb', line 64 def to_h { gem_name: gem_name, severity: severity.to_s, reasons: reasons.map(&:to_h), gemfile_line: gemfile_line, gemfile_group: gemfile_group, suggestion: suggestion } end |
#type_label ⇒ Object
52 53 54 |
# File 'lib/gemxray/result.rb', line 52 def type_label reason_types.map { |type| type.to_s.tr("_", "-") }.join(" + ") end |