Class: RightGit::Git::Commit
- Inherits:
-
Object
- Object
- RightGit::Git::Commit
- Defined in:
- lib/right_git/git/commit.rb
Overview
A commit within a Git repository.
Defined Under Namespace
Classes: CommitError
Constant Summary collapse
- COMMIT_INFO =
/^([0-9A-Fa-f]+) ([0-9]+) (.*)$/- COMMIT_SHA1_REGEX =
/^[0-9a-fA-F]{40}$/
Instance Attribute Summary collapse
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Class Method Summary collapse
-
.sha?(revision) ⇒ TrueClass|FalseClass
True if the given revision is a (fully qualified, not abbreviated) commit SHA.
Instance Method Summary collapse
-
#author ⇒ String
Author of commit.
-
#hash ⇒ String
Hash of commit (may be abbreviated).
-
#initialize(repo, line) ⇒ Commit
constructor
A new instance of Commit.
-
#timestamp ⇒ Time
Time of commit.
-
#to_s ⇒ String
(also: #inspect)
Stringized.
Constructor Details
#initialize(repo, line) ⇒ Commit
Returns a new instance of Commit.
40 41 42 43 44 45 46 |
# File 'lib/right_git/git/commit.rb', line 40 def initialize(repo, line) @repo = repo unless match = COMMIT_INFO.match(line) raise CommitError, "Unrecognized commit summary: #{line.inspect}" end @info = [ match[1], Integer(match[2]), match[3] ] end |
Instance Attribute Details
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
34 35 36 |
# File 'lib/right_git/git/commit.rb', line 34 def repo @repo end |
Class Method Details
.sha?(revision) ⇒ TrueClass|FalseClass
Returns true if the given revision is a (fully qualified, not abbreviated) commit SHA.
71 72 73 |
# File 'lib/right_git/git/commit.rb', line 71 def self.sha?(revision) !!COMMIT_SHA1_REGEX.match(revision) end |
Instance Method Details
#author ⇒ String
Returns author of commit.
66 67 68 |
# File 'lib/right_git/git/commit.rb', line 66 def @info[2] end |
#hash ⇒ String
Returns hash of commit (may be abbreviated).
55 56 57 58 |
# File 'lib/right_git/git/commit.rb', line 55 def hash # This overrides String#hash on purpose @info[0] end |
#timestamp ⇒ Time
Returns time of commit.
61 62 63 |
# File 'lib/right_git/git/commit.rb', line 61 def ::Time.at(@info[1]) end |
#to_s ⇒ String Also known as: inspect
Returns stringized.
49 50 51 |
# File 'lib/right_git/git/commit.rb', line 49 def to_s "#{self.class.name}: #{@info.inspect}" end |