Class: GitReviewer::DiffFile
- Inherits:
-
Object
- Object
- GitReviewer::DiffFile
- Defined in:
- lib/gitreviewer/analyze/diff_tree.rb
Constant Summary collapse
- UNKNOWN =
未知情况,理论上不存在
0- DELETE =
删除文件
1- ADD =
新增文件
2- MODIFY =
修改文件
3
Instance Attribute Summary collapse
-
#binary ⇒ Object
writeonly
Sets the attribute binary.
-
#diff_lines ⇒ Object
Returns the value of attribute diff_lines.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#operation ⇒ Object
Returns the value of attribute operation.
Instance Method Summary collapse
- #binary? ⇒ Boolean
- #format_file_name ⇒ Object
- #format_line_diff ⇒ Object
- #format_operation ⇒ Object
- #format_property ⇒ Object
-
#initialize(file_name, diff_lines, operation, binary) ⇒ DiffFile
constructor
A new instance of DiffFile.
- #print_meta_info ⇒ Object
Constructor Details
#initialize(file_name, diff_lines, operation, binary) ⇒ DiffFile
23 24 25 26 27 28 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 23 def initialize(file_name, diff_lines, operation, binary) @file_name = file_name @diff_lines = diff_lines @operation = operation @binary = binary end |
Instance Attribute Details
#binary=(value) ⇒ Object (writeonly)
Sets the attribute binary
17 18 19 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 17 def binary=(value) @binary = value end |
#diff_lines ⇒ Object
Returns the value of attribute diff_lines.
15 16 17 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 15 def diff_lines @diff_lines end |
#file_name ⇒ Object
Returns the value of attribute file_name.
14 15 16 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 14 def file_name @file_name end |
#operation ⇒ Object
Returns the value of attribute operation.
13 14 15 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 13 def operation @operation end |
Instance Method Details
#binary? ⇒ Boolean
19 20 21 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 19 def binary? @binary end |
#format_file_name ⇒ Object
76 77 78 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 76 def format_file_name return "filename: #{file_name}\n" end |
#format_line_diff ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 80 def format_line_diff name_max_length = 0 result = [] diff_lines.each_with_index do |line, index| name_max_length = [name_max_length, line.format_user.length].max if line.is_unchange if result.size == 0 || !result.last.is_unchange result.append(line) end else result.append(line) end end name_max_length += 2 format_content = "" result.each do |line| if line.operation == DiffLine::DELETE format_content += "\033[0;31m#{line.source_line.user.rjust(name_max_length)} #{line.source_line.format_line} - #{line.source_line.description}\033[0m\n" elsif line.operation == DiffLine::ADD format_content += "\033[0;32m#{line.target_line.user.rjust(name_max_length)} #{line.target_line.format_line} + #{line.target_line.description}\033[0m\n" else format_content += "...\n" end end return format_content end |
#format_operation ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 63 def format_operation case @operation when DiffFile::UNKNOWN return "UNKNOWN" when DiffFile::DELETE return "DELETE" when DiffFile::ADD return "ADD" when DiffFile::MODIFY return "MODIFY" end end |
#format_property ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 42 def format_property result = "" case @operation when DiffFile::UNKNOWN result += "operation: UNKNOWN \n" when DiffFile::DELETE result += "operation: DELETE \n" when DiffFile::ADD result += "operation: ADD \n" when DiffFile::MODIFY result += "operation: MODIFY \n" end if binary? result += "binary: true \n" else result += "binary: false \n" end return result end |
#print_meta_info ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gitreviewer/analyze/diff_tree.rb', line 30 def rows = [ ["filename", file_name], ["operation", format_operation], ["binary", binary?] ] table = Terminal::Table.new do |t| t.rows = rows end Printer.verbose_put table end |