Class: GitStatistics::DiffSummary
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- GitStatistics::DiffSummary
- Defined in:
- lib/git_statistics/diff_summary.rb
Instance Method Summary collapse
-
#additions ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old).
-
#blob ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old).
-
#deletions ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old).
- #filename ⇒ Object
-
#initialize(repo, patch) ⇒ DiffSummary
constructor
A new instance of DiffSummary.
- #inspect ⇒ Object
-
#language ⇒ Object
Determine the language of the file from the blob.
- #net ⇒ Object
- #similarity ⇒ Object
-
#status ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old).
- #to_json ⇒ Object
Constructor Details
#initialize(repo, patch) ⇒ DiffSummary
Returns a new instance of DiffSummary.
3 4 5 6 |
# File 'lib/git_statistics/diff_summary.rb', line 3 def initialize(repo, patch) @repo = repo super(patch) end |
Instance Method Details
#additions ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old)
9 10 11 |
# File 'lib/git_statistics/diff_summary.rb', line 9 def additions __getobj__.deletions end |
#blob ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old)
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/git_statistics/diff_summary.rb', line 46 def blob if status == :deleted @repo.lookup(delta.new_file[:oid]) # Look at new instead of old else @repo.lookup(delta.old_file[:oid]) # Look at old instead of new end rescue Rugged::OdbError Log.warn 'Could not find object (most likely a submodule)' nil end |
#deletions ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old)
14 15 16 |
# File 'lib/git_statistics/diff_summary.rb', line 14 def deletions __getobj__.additions end |
#filename ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/git_statistics/diff_summary.rb', line 37 def filename if status == :deleted delta.old_file[:path] else delta.new_file[:path] end end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/git_statistics/diff_summary.rb', line 57 def inspect "<GitStatistics::FileStat @filename=#{filename} @status=#{status} @similarity=#{similarity} @language=#{language} @additions=#{additions}, @deletions=#{deletions}, @net=#{net}>" end |
#language ⇒ Object
Determine the language of the file from the blob
66 67 68 69 70 71 72 73 |
# File 'lib/git_statistics/diff_summary.rb', line 66 def language language = 'Unknown' unless blob.nil? detected_language = LanguageSniffer.detect(filename, content: blob.content).language language = detected_language.name unless detected_language.nil? end language end |
#net ⇒ Object
18 19 20 |
# File 'lib/git_statistics/diff_summary.rb', line 18 def net additions - deletions end |
#similarity ⇒ Object
33 34 35 |
# File 'lib/git_statistics/diff_summary.rb', line 33 def similarity delta.similarity end |
#status ⇒ Object
We flip these around since we are diffing in the opposite direction – new.diff(old)
23 24 25 26 27 28 29 30 31 |
# File 'lib/git_statistics/diff_summary.rb', line 23 def status if delta.status == :deleted return :added elsif delta.status == :added return :deleted else return delta.status end end |
#to_json ⇒ Object
61 62 63 |
# File 'lib/git_statistics/diff_summary.rb', line 61 def to_json { filename: filename, status: status, similarity: similarity, language: language, additions: additions, deletions: deletions, net: net } end |