Class: GitCommitMailer::FileDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/git-commit-mailer/file-diff.rb

Constant Summary collapse

CHANGED_TYPE =
{
  :added    => "Added",
  :modified => "Modified",
  :deleted  => "Deleted",
  :copied   => "Copied",
  :renamed  => "Renamed",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailer, lines, revision) ⇒ FileDiff

Returns a new instance of FileDiff.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/git-commit-mailer/file-diff.rb', line 31

def initialize(mailer, lines, revision)
  @mailer = mailer
  @index = nil
  @body = ''
  @changes = []

  @type = :modified
  @is_binary = false
  @is_mode_changed = false

  @old_blob = @new_blob = nil

  parse_header(lines)
  (revision)
  parse_extended_headers(lines)
  parse_body(lines)
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



29
30
31
# File 'lib/git-commit-mailer/file-diff.rb', line 29

def changes
  @changes
end

#indexObject

Returns the value of attribute index.



30
31
32
# File 'lib/git-commit-mailer/file-diff.rb', line 30

def index
  @index
end

Instance Method Details

#file_pathObject



49
50
51
# File 'lib/git-commit-mailer/file-diff.rb', line 49

def file_path
  @to_file
end

#formatObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/git-commit-mailer/file-diff.rb', line 62

def format
  formatted_diff = format_header

  if @mailer.add_diff?
    formatted_diff << headers + @body
  else
    formatted_diff << git_command
  end

  formatted_diff
end

#format_headerObject



53
54
55
56
57
58
59
60
# File 'lib/git-commit-mailer/file-diff.rb', line 53

def format_header
  header = "  #{CHANGED_TYPE[@type]}: #{@to_file} "
  header << "(+#{@added_line} -#{@deleted_line})"
  header << "#{format_file_mode}#{format_similarity_index}\n"
  header << "  Mode: #{@old_mode} -> #{@new_mode}\n" if @is_mode_changed
  header << diff_separator
  header
end