Class: GitDiffLCS::Stat

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

Overview

Stat

Constant Summary collapse

SRC_FOLDER =

Source folder

"src_#{SecureRandom.uuid}"
DEST_FOLDER =

Destination folder

"dest_#{SecureRandom.uuid}"
INIT_COUNT =

Initial diff count number

[0, 0, 0].freeze
INIT_ARRAY =

Initial array for target_files and errors

Array.new(2, [])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, src, dest) ⇒ Stat

initialize GitDiffLCS::Stat

Arguments:

[String] repo: repo git repository address
[String] src: src src commit or branch
[String] dest: dest commit or branch


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/git_diff_lcs/stat.rb', line 34

def initialize(repo, src, dest)
  @go_next = false
  @dir = Dir.mktmpdir
  @add, @del, @mod = *INIT_COUNT
  @target_files, @errors = *Array.new(2, [])
  @diff = git_clone(repo, src, dest).diff(src, dest)
  calculate
rescue Git::GitExecuteError
  @errors << "[ERROR] wrong git info(repository or src or dest)"
ensure
  FileUtils.rm_rf(@dir)
end

Instance Attribute Details

#addObject (readonly) Also known as: insertions

Returns the value of attribute add.



23
24
25
# File 'lib/git_diff_lcs/stat.rb', line 23

def add
  @add
end

#delObject (readonly) Also known as: deletions

Returns the value of attribute del.



23
24
25
# File 'lib/git_diff_lcs/stat.rb', line 23

def del
  @del
end

#errorsObject (readonly)

Returns the value of attribute errors.



23
24
25
# File 'lib/git_diff_lcs/stat.rb', line 23

def errors
  @errors
end

#modObject (readonly) Also known as: modifications

Returns the value of attribute mod.



23
24
25
# File 'lib/git_diff_lcs/stat.rb', line 23

def mod
  @mod
end

Instance Method Details

#summaryObject

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

Return:

[String] diff summary

Example:

>> stat = GitDiffLCS::Stat.new("https://github.com/btpink-seo/git-diff-lcs.git", "test/src", "test/dest")
>> stat.summary
=> 5 files changed, 13 insertions(+), 6 deletions(-), 2 modifications(!), total(21)


57
58
59
60
61
# File 'lib/git_diff_lcs/stat.rb', line 57

def summary
  total = @add + @del + @mod
  changed = @target_files.size
  "#{changed} files changed, #{@add} insertions(+), #{@del} deletions(-), #{@mod} modifications(!), total(#{total})"
end