class GitPlus::Parsers::Commits::Saved::History

Parses saved commit history into commit objects.

Constants

PATTERN

Attributes

entry[R]
log[R]
pattern[R]

Public Class Methods

new(pattern: PATTERN, entry: Entry, log: Commands::Log.new) click to toggle source
# File lib/git_plus/parsers/commits/saved/history.rb, line 26
def initialize pattern: PATTERN, entry: Entry, log: Commands::Log.new
  @pattern = pattern
  @entry = entry
  @log = log
end

Public Instance Methods

call(*arguments) click to toggle source
# File lib/git_plus/parsers/commits/saved/history.rb, line 32
def call *arguments
  arguments.including(format)
           .then { |pretty_format| process(*pretty_format) }
           .map { |response| parse response }
           .map { |attributes| entry.call(**attributes) }
end

Private Instance Methods

format() click to toggle source
# File lib/git_plus/parsers/commits/saved/history.rb, line 43
def format
  pattern.reduce("") { |string, (key, value)| string + "<#{key}>#{value}</#{key}>%n" }
         .then { |structure| %(--pretty=format:"#{structure}") }
end
parse(response) click to toggle source
# File lib/git_plus/parsers/commits/saved/history.rb, line 54
def parse response
  pattern.keys.reduce({}) do |body, key|
    body.merge key => String(response[%r(<#{key}>(?<content>.*?)</#{key}>)m, :content])
  end
end
process(*arguments) click to toggle source
# File lib/git_plus/parsers/commits/saved/history.rb, line 48
def process *arguments
  log.call(*arguments).then do |stdout, _stderr, status|
    status.success? ? stdout.scrub("?").split(%(\"\n\")) : []
  end
end