Class: Shiba::Review::ExplainDiff
- Inherits:
-
Object
- Object
- Shiba::Review::ExplainDiff
- Defined in:
- lib/shiba/review/explain_diff.rb
Overview
Given an explain log and a diff, returns any explain logs that appear to be caused by the diff.
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #diff_requested_by_user? ⇒ Boolean
-
#initialize(log, options) ⇒ ExplainDiff
constructor
A new instance of ExplainDiff.
-
#problems ⇒ Object
Returns detected problem queries with their line numbers.
- #result ⇒ Object
Constructor Details
#initialize(log, options) ⇒ ExplainDiff
Returns a new instance of ExplainDiff.
16 17 18 19 |
# File 'lib/shiba/review/explain_diff.rb', line 16 def initialize(log, ) @log = log @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/shiba/review/explain_diff.rb', line 14 def @options end |
Instance Method Details
#diff_requested_by_user? ⇒ Boolean
21 22 23 |
# File 'lib/shiba/review/explain_diff.rb', line 21 def diff_requested_by_user? [ "staged", "unstaged", "branch", "diff" ].any? { |key| @options.key?(key) } end |
#problems ⇒ Object
Returns detected problem queries with their line numbers. Query problem format is [ [ “path:lineno”, explain ]… ]
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shiba/review/explain_diff.rb', line 27 def problems return @problems if @problems @problems = explains_with_backtrace_in_diff.select do |explain| explain["severity"] && explain["severity"] != 'none' end if ["verbose"] $stderr.puts @problems $stderr.puts "Updated lines: #{updated_lines}" end @problems.map! do |problem| line = diff_line_from_backtrace(problem["backtrace"]) next if line.nil? [ line, problem ] end @problems.compact! @problems end |
#result ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shiba/review/explain_diff.rb', line 50 def result msg = nil if changed_files.empty? if ['verbose'] msg = "No changes found. Are you sure you specified the correct branch?" end return Result.new(:pass, msg) end if problems.empty? msg = "No problems found caused by the diff" return Result.new(:pass, msg) end return Result.new(:fail, "Potential problems") end |