Class: Database::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/database/commit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parents, tree, author, committer, message) ⇒ Commit

Returns a new instance of Commit.



28
29
30
31
32
33
34
# File 'lib/database/commit.rb', line 28

def initialize(parents, tree, author, committer, message)
  @parents   = parents
  @tree      = tree
  @author    = author
  @committer = committer
  @message   = message
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



7
8
9
# File 'lib/database/commit.rb', line 7

def author
  @author
end

#committerObject (readonly)

Returns the value of attribute committer.



7
8
9
# File 'lib/database/commit.rb', line 7

def committer
  @committer
end

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/database/commit.rb', line 7

def message
  @message
end

#oidObject

Returns the value of attribute oid.



6
7
8
# File 'lib/database/commit.rb', line 6

def oid
  @oid
end

#parentsObject (readonly)

Returns the value of attribute parents.



7
8
9
# File 'lib/database/commit.rb', line 7

def parents
  @parents
end

#treeObject (readonly)

Returns the value of attribute tree.



7
8
9
# File 'lib/database/commit.rb', line 7

def tree
  @tree
end

Class Method Details

.parse(scanner) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/database/commit.rb', line 9

def self.parse(scanner)
  headers = Hash.new { |hash, key| hash[key] = [] }

  loop do
    line = scanner.scan_until(/\n/).strip
    break if line == ""

    key, value = line.split(/ +/, 2)
    headers[key].push(value)
  end

  Commit.new(
    headers["parent"],
    headers["tree"].first,
    Author.parse(headers["author"].first),
    Author.parse(headers["committer"].first),
    scanner.rest)
end

Instance Method Details

#dateObject



44
45
46
# File 'lib/database/commit.rb', line 44

def date
  @committer.time
end

#merge?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/database/commit.rb', line 36

def merge?
  @parents.size > 1
end

#parentObject



40
41
42
# File 'lib/database/commit.rb', line 40

def parent
  @parents.first
end

#title_lineObject



48
49
50
# File 'lib/database/commit.rb', line 48

def title_line
  @message.lines.first
end

#to_sObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/database/commit.rb', line 56

def to_s
  lines = []

  lines.push("tree #{ @tree }")
  lines.concat(@parents.map { |oid| "parent #{ oid }" })
  lines.push("author #{ @author }")
  lines.push("committer #{ @committer }")
  lines.push("")
  lines.push(@message)

  lines.join("\n")
end

#typeObject



52
53
54
# File 'lib/database/commit.rb', line 52

def type
  "commit"
end