Class: Lolcommits::GitInfo
- Inherits:
-
Object
- Object
- Lolcommits::GitInfo
- Defined in:
- lib/lolcommits/backends/git_info.rb
Constant Summary collapse
- GIT_URL_REGEX =
%r{.*:([/\w-]*).git}
Class Method Summary collapse
Instance Method Summary collapse
- #author_email ⇒ Object
- #author_name ⇒ Object
- #branch ⇒ Object
- #commit_date ⇒ Object
-
#initialize ⇒ GitInfo
constructor
A new instance of GitInfo.
- #message ⇒ Object
- #repo ⇒ Object
- #repo_internal_path ⇒ Object
- #sha ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize ⇒ GitInfo
Returns a new instance of GitInfo.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lolcommits/backends/git_info.rb', line 13 def initialize debug "parsed the following values from commit:" debug "\t#{}" debug "\t#{sha}" debug "\t#{repo_internal_path}" debug "\t#{repo}" debug "\t#{branch}" debug "\t#{commit_date}" debug "\t#{}" if debug "\t#{}" if end |
Class Method Details
.local_name(path = ".") ⇒ Object
9 10 11 |
# File 'lib/lolcommits/backends/git_info.rb', line 9 def self.local_name(path = ".") File.basename(Git.open(path).dir.to_s) end |
.repo_root?(path = ".") ⇒ Boolean
5 6 7 |
# File 'lib/lolcommits/backends/git_info.rb', line 5 def self.repo_root?(path = ".") File.directory?(File.join(path, ".git")) end |
Instance Method Details
#author_email ⇒ Object
64 65 66 |
# File 'lib/lolcommits/backends/git_info.rb', line 64 def @author_email ||= last_commit..email if last_commit. end |
#author_name ⇒ Object
60 61 62 |
# File 'lib/lolcommits/backends/git_info.rb', line 60 def @author_name ||= last_commit..name if last_commit. end |
#branch ⇒ Object
25 26 27 |
# File 'lib/lolcommits/backends/git_info.rb', line 25 def branch @branch ||= repository.current_branch end |
#commit_date ⇒ Object
68 69 70 |
# File 'lib/lolcommits/backends/git_info.rb', line 68 def commit_date @commit_date ||= last_commit.date.utc end |
#message ⇒ Object
29 30 31 32 33 34 |
# File 'lib/lolcommits/backends/git_info.rb', line 29 def @message ||= begin = last_commit. || "" .split("\n").first end end |
#repo ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lolcommits/backends/git_info.rb', line 48 def repo @repo ||= begin match = repository.remote.url.match(GIT_URL_REGEX) if remote_repo? if match match[1] elsif !repository.repo.path.empty? repository.repo.path.split(File::SEPARATOR)[-2] end end end |
#repo_internal_path ⇒ Object
40 41 42 |
# File 'lib/lolcommits/backends/git_info.rb', line 40 def repo_internal_path @repo_internal_path ||= repository.repo.path end |
#sha ⇒ Object
36 37 38 |
# File 'lib/lolcommits/backends/git_info.rb', line 36 def sha @sha ||= last_commit.sha[0..10] end |
#url ⇒ Object
44 45 46 |
# File 'lib/lolcommits/backends/git_info.rb', line 44 def url @url ||= remote_repo? ? remote_https_url(repository.remote&.url) : nil end |