Class: Avm::Git::AutoCommit::Rules::Manual::WithFile

Inherits:
Base::WithFile show all
Defined in:
lib/avm/git/auto_commit/rules/manual.rb

Constant Summary collapse

COMMIT_FORMAT =
'%h - %s (%cr)'
SKIP_OPTION =
's'

Instance Method Summary collapse

Methods inherited from Base::WithFile

#new_commit_info

Instance Method Details

#commit_infoObject



16
17
18
19
20
21
22
23
# File 'lib/avm/git/auto_commit/rules/manual.rb', line 16

def commit_info
  return nil unless file.commits.any?

  commits_banner
  input('Which commit?', list: commits_by_position).if_present do |v|
    new_commit_info.fixup(v)
  end
end

#commits_bannerObject



25
26
27
28
29
30
# File 'lib/avm/git/auto_commit/rules/manual.rb', line 25

def commits_banner
  file.commits.each_with_index do |commit, _index|
    infov "    #{commit.position}", format_commit(commit)
  end
  infov "    #{SKIP_OPTION}", 'skip'
end

#commits_by_positionObject



32
33
34
35
# File 'lib/avm/git/auto_commit/rules/manual.rb', line 32

def commits_by_position
  (file.commits.map { |commit| [commit.position.to_s, commit] } + [[SKIP_OPTION, nil]])
    .to_h
end

#format_commit(commit) ⇒ Object



37
38
39
# File 'lib/avm/git/auto_commit/rules/manual.rb', line 37

def format_commit(commit)
  commit.format(COMMIT_FORMAT)
end