Class: Mbeditor::GitBlameService
- Inherits:
-
Object
- Object
- Mbeditor::GitBlameService
- Includes:
- GitService
- Defined in:
- app/services/mbeditor/git_blame_service.rb
Overview
Wraps ‘git blame –porcelain` and returns structured per-line blame data.
Each result entry:
{
"line" => Integer, # 1-indexed line number
"sha" => String, # full 40-char commit sha
"author" => String,
"email" => String,
"date" => String, # ISO-8601
"summary" => String, # commit subject line
"content" => String # raw source line (without trailing newline)
}
Constant Summary
Constants included from GitService
Mbeditor::GitService::SAFE_GIT_REF
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
Instance Method Summary collapse
-
#call ⇒ Object
Returns Array of line blame hashes, or raises RuntimeError.
-
#initialize(repo_path:, file_path:) ⇒ GitBlameService
constructor
A new instance of GitBlameService.
Methods included from GitService
ahead_behind, current_branch, parse_git_log, parse_git_log_with_parents, resolve_path, run_git, upstream_branch
Constructor Details
#initialize(repo_path:, file_path:) ⇒ GitBlameService
Returns a new instance of GitBlameService.
23 24 25 26 |
# File 'app/services/mbeditor/git_blame_service.rb', line 23 def initialize(repo_path:, file_path:) @repo_path = repo_path.to_s @file_path = file_path.to_s end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
21 22 23 |
# File 'app/services/mbeditor/git_blame_service.rb', line 21 def file_path @file_path end |
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
21 22 23 |
# File 'app/services/mbeditor/git_blame_service.rb', line 21 def repo_path @repo_path end |
Instance Method Details
#call ⇒ Object
Returns Array of line blame hashes, or raises RuntimeError.
29 30 31 32 33 34 |
# File 'app/services/mbeditor/git_blame_service.rb', line 29 def call output, status = GitService.run_git(repo_path, "blame", "--porcelain", "--", file_path) raise "git blame failed for #{file_path}" unless status.success? parse_porcelain(output) end |