debtective 0.2.3.3 → 0.2.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "debtective/find_commit"
4
-
5
- module Debtective
6
- module Todos
7
- # Hold todo information
8
- class Todo
9
- class << self
10
- # @return [Debtective::Todos::Todo]
11
- def build(pathname, index)
12
- Build.new(pathname, index).call
13
- end
14
- end
15
-
16
- attr_accessor :pathname, :todo_boundaries, :statement_boundaries
17
-
18
- # @param pathname [Pathname]
19
- # @param lines [Array<String>]
20
- # @param todo_boundaries [Range]
21
- # @param statement_boundaries [Range]
22
- def initialize(pathname, lines, todo_boundaries, statement_boundaries)
23
- @pathname = pathname
24
- @lines = lines
25
- @todo_boundaries = todo_boundaries
26
- @statement_boundaries = statement_boundaries
27
- end
28
-
29
- # location in the codebase
30
- # @return [String]
31
- def location
32
- "#{@pathname}:#{@todo_boundaries.min + 1}"
33
- end
34
-
35
- # size of the todo code
36
- # @return [Integer]
37
- def size
38
- @statement_boundaries.size
39
- end
40
-
41
- # return commit that introduced the todo
42
- # @return [Git::Object::Commit]
43
- def commit
44
- @commit ||= Debtective::FindCommit.new(@pathname, @lines[@todo_boundaries.min]).call
45
- end
46
-
47
- # @return [Integer]
48
- def days
49
- return if commit.time.nil?
50
-
51
- ((Time.now - commit.time) / (24 * 60 * 60)).round
52
- end
53
-
54
- # @return [Hash]
55
- def to_h
56
- {
57
- pathname: pathname,
58
- location: location,
59
- todo_boundaries: todo_boundaries.minmax,
60
- statement_boundaries: statement_boundaries.minmax,
61
- size: size,
62
- commit: {
63
- sha: commit.sha,
64
- author: commit.author.to_h,
65
- time: commit.time
66
- }
67
- }
68
- end
69
- end
70
- end
71
- end