Class: Git::Log::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/Git/Log.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ Commit

Returns a new instance of Commit.



66
67
68
69
70
71
72
# File 'lib/Git/Log.rb', line 66

def initialize(values = {})
  @hash = values[:hash]
  @merge = values[:merge]
  @author = values[:author]
  @date = values[:date]
  @message = values[:message]
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



62
63
64
# File 'lib/Git/Log.rb', line 62

def author
  @author
end

#dateObject (readonly)

Returns the value of attribute date.



63
64
65
# File 'lib/Git/Log.rb', line 63

def date
  @date
end

#hashObject (readonly)

class << self



60
61
62
# File 'lib/Git/Log.rb', line 60

def hash
  @hash
end

#mergeObject (readonly)

Returns the value of attribute merge.



61
62
63
# File 'lib/Git/Log.rb', line 61

def merge
  @merge
end

#messageObject (readonly)

Returns the value of attribute message.



64
65
66
# File 'lib/Git/Log.rb', line 64

def message
  @message
end

Class Method Details

.parse(commit_string) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/Git/Log.rb', line 29

def parse(commit_string)
  hash = merge = author = date = message = ''
  commit_string.split("\n").each do |line|
    case line.strip
    when /^commit (\w+)/
      hash = line.strip.capture(/^commit (\w+)/)
    when /^Merge: /
      merge = line.strip.gsub(/^Merge: /, '')
    when /^Author: /
      author = line.strip.gsub(/^Author: /, '')
    when /^Date:   /
      date = line.strip.gsub(/^Date:   /, '')
    else
      if line.strip.empty?
        (message ||= '') << "\n\n"
      else
        (message ||= '') << line.lstrip
      end
    end
  end
  commit_args = {
    hash: hash,
    author: author,
    date: date,
    message: message.lstrip
  }
  commit_args.merge!(merge: merge)
  Commit.new(commit_args)
end