Class: Git::AuthorInfo
- Inherits:
-
Data
- Object
- Data
- Git::AuthorInfo
- Defined in:
- lib/git/author_info.rb
Overview
Immutable value object representing an author or committer identity
This is a lightweight, immutable data structure holding the identity data git records for commit authors, committers, and taggers. It replaces the mutable Author, which is deprecated.
Instance Attribute Summary collapse
-
#date ⇒ Time?
readonly
The timestamp of the change, or
nilif not available. -
#email ⇒ String?
readonly
The person's email address, or
nilif not available. -
#name ⇒ String?
readonly
The person's name, or
nilif not available.
Class Method Summary collapse
-
.parse(author_string) ⇒ Git::AuthorInfo
Parses a raw git identity string into a Git::AuthorInfo.
Instance Attribute Details
#date ⇒ Time? (readonly)
Returns the timestamp of the change, or nil if not available.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/git/author_info.rb', line 38 AuthorInfo = Data.define(:name, :email, :date) do # Parses a raw git identity string into a Git::AuthorInfo # # The expected format is `"Name <email> timestamp offset"` as emitted by # `git cat-file` for the `author`, `committer`, and `tagger` headers. The # timestamp is interpreted as seconds since the Unix epoch; the timezone # offset is not preserved in the resulting `date`. # # @example Parse a well-formed identity string # Git::AuthorInfo.parse('John Doe <[email protected]> 1627849923 +0200') # #=> #<data Git::AuthorInfo name="John Doe", email="[email protected]", ...> # # @example A string that does not match the expected format # Git::AuthorInfo.parse('garbage') # #=> #<data Git::AuthorInfo name=nil, email=nil, date=nil> # # @param author_string [String] the raw identity string to parse # # @return [Git::AuthorInfo] the parsed identity; all attributes are `nil` # when the string does not match the expected format # def self.parse() match = /(.*?) <(.*?)> (\d+) (.*)/.match() return new(name: nil, email: nil, date: nil) unless match new(name: match[1], email: match[2], date: Time.at(match[3].to_i)) end end |
#email ⇒ String? (readonly)
Returns the person's email address, or nil if not available.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/git/author_info.rb', line 38 AuthorInfo = Data.define(:name, :email, :date) do # Parses a raw git identity string into a Git::AuthorInfo # # The expected format is `"Name <email> timestamp offset"` as emitted by # `git cat-file` for the `author`, `committer`, and `tagger` headers. The # timestamp is interpreted as seconds since the Unix epoch; the timezone # offset is not preserved in the resulting `date`. # # @example Parse a well-formed identity string # Git::AuthorInfo.parse('John Doe <[email protected]> 1627849923 +0200') # #=> #<data Git::AuthorInfo name="John Doe", email="[email protected]", ...> # # @example A string that does not match the expected format # Git::AuthorInfo.parse('garbage') # #=> #<data Git::AuthorInfo name=nil, email=nil, date=nil> # # @param author_string [String] the raw identity string to parse # # @return [Git::AuthorInfo] the parsed identity; all attributes are `nil` # when the string does not match the expected format # def self.parse() match = /(.*?) <(.*?)> (\d+) (.*)/.match() return new(name: nil, email: nil, date: nil) unless match new(name: match[1], email: match[2], date: Time.at(match[3].to_i)) end end |
#name ⇒ String? (readonly)
Returns the person's name, or nil if not available.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/git/author_info.rb', line 38 AuthorInfo = Data.define(:name, :email, :date) do # Parses a raw git identity string into a Git::AuthorInfo # # The expected format is `"Name <email> timestamp offset"` as emitted by # `git cat-file` for the `author`, `committer`, and `tagger` headers. The # timestamp is interpreted as seconds since the Unix epoch; the timezone # offset is not preserved in the resulting `date`. # # @example Parse a well-formed identity string # Git::AuthorInfo.parse('John Doe <[email protected]> 1627849923 +0200') # #=> #<data Git::AuthorInfo name="John Doe", email="[email protected]", ...> # # @example A string that does not match the expected format # Git::AuthorInfo.parse('garbage') # #=> #<data Git::AuthorInfo name=nil, email=nil, date=nil> # # @param author_string [String] the raw identity string to parse # # @return [Git::AuthorInfo] the parsed identity; all attributes are `nil` # when the string does not match the expected format # def self.parse() match = /(.*?) <(.*?)> (\d+) (.*)/.match() return new(name: nil, email: nil, date: nil) unless match new(name: match[1], email: match[2], date: Time.at(match[3].to_i)) end end |
Class Method Details
.parse(author_string) ⇒ Git::AuthorInfo
Parses a raw git identity string into a Git::AuthorInfo
The expected format is "Name <email> timestamp offset" as emitted by
git cat-file for the author, committer, and tagger headers. The
timestamp is interpreted as seconds since the Unix epoch; the timezone
offset is not preserved in the resulting date.
59 60 61 62 63 64 |
# File 'lib/git/author_info.rb', line 59 def self.parse() match = /(.*?) <(.*?)> (\d+) (.*)/.match() return new(name: nil, email: nil, date: nil) unless match new(name: match[1], email: match[2], date: Time.at(match[3].to_i)) end |