Class: GitDiffLCS::Shortstat

Inherits:
Object
  • Object
show all
Defined in:
lib/git_diff_lcs/shortstat.rb

Overview

Shortstat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git_target, src, dest) ⇒ Shortstat

initialize GitDiffLCS::Shortstat

Arguments:

[String] git_target: git repository address or working directory
[String] src: commit or branch
[String] dest: commit or branch


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/git_diff_lcs/shortstat.rb', line 20

def initialize(git_target, src, dest)
  @dir = Dir.mktmpdir
  @add, @del, @mod = *GitDiffLCS::INIT_COUNT
  @errors = []
  @git = GitDiffLCS::LibGit.new(git_target, @dir, src, dest)
  calculate
rescue Git::GitExecuteError, ArgumentError
  @errors << "[ERROR] wrong arguments"
ensure
  FileUtils.rm_rf(@dir)
end

Instance Attribute Details

#addObject (readonly) Also known as: insertions

Returns the value of attribute add.



9
10
11
# File 'lib/git_diff_lcs/shortstat.rb', line 9

def add
  @add
end

#delObject (readonly) Also known as: deletions

Returns the value of attribute del.



9
10
11
# File 'lib/git_diff_lcs/shortstat.rb', line 9

def del
  @del
end

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/git_diff_lcs/shortstat.rb', line 9

def errors
  @errors
end

#modObject (readonly) Also known as: modifications

Returns the value of attribute mod.



9
10
11
# File 'lib/git_diff_lcs/shortstat.rb', line 9

def mod
  @mod
end

Instance Method Details

#summaryObject

Get diff summary changed files, insertions, deletions, modifications and total

Return:

[String] diff summary


37
38
39
40
41
# File 'lib/git_diff_lcs/shortstat.rb', line 37

def summary
  " #{@git.diff.name_status.keys.size} files changed, "\
  "#{@add} insertions(+), #{@del} deletions(-), #{@mod} modifications(!), "\
  "total(#{@add + @del + @mod})"
end