Class: Database::Commit
- Inherits:
-
Object
- Object
- Database::Commit
- Defined in:
- lib/database/commit.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#committer ⇒ Object
readonly
Returns the value of attribute committer.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#oid ⇒ Object
Returns the value of attribute oid.
-
#parents ⇒ Object
readonly
Returns the value of attribute parents.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Class Method Summary collapse
Instance Method Summary collapse
- #date ⇒ Object
-
#initialize(parents, tree, author, committer, message) ⇒ Commit
constructor
A new instance of Commit.
- #merge? ⇒ Boolean
- #parent ⇒ Object
- #title_line ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
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, , committer, ) @parents = parents @tree = tree @author = @committer = committer @message = end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
7 8 9 |
# File 'lib/database/commit.rb', line 7 def @author end |
#committer ⇒ Object (readonly)
Returns the value of attribute committer.
7 8 9 |
# File 'lib/database/commit.rb', line 7 def committer @committer end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/database/commit.rb', line 7 def @message end |
#oid ⇒ Object
Returns the value of attribute oid.
6 7 8 |
# File 'lib/database/commit.rb', line 6 def oid @oid end |
#parents ⇒ Object (readonly)
Returns the value of attribute parents.
7 8 9 |
# File 'lib/database/commit.rb', line 7 def parents @parents end |
#tree ⇒ Object (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
#date ⇒ Object
44 45 46 |
# File 'lib/database/commit.rb', line 44 def date @committer.time end |
#merge? ⇒ Boolean
36 37 38 |
# File 'lib/database/commit.rb', line 36 def merge? @parents.size > 1 end |
#parent ⇒ Object
40 41 42 |
# File 'lib/database/commit.rb', line 40 def parent @parents.first end |
#title_line ⇒ Object
48 49 50 |
# File 'lib/database/commit.rb', line 48 def title_line @message.lines.first end |
#to_s ⇒ Object
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 |
#type ⇒ Object
52 53 54 |
# File 'lib/database/commit.rb', line 52 def type "commit" end |