Class: Changelogger::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/changelogger/branches_window.rb

Overview

Changelogger::Graph caches ‘git log –graph` output for rendering.

Constant Summary collapse

FILENAME =

Changelogger::Graph::FILENAME stores the graph cache file name.

'.graph'

Class Method Summary collapse

Class Method Details

.buildString

Changelogger::Graph.build -> String

Reads the cached graph content (regenerates if missing).

Returns:

  • (String)


46
47
48
49
# File 'lib/changelogger/branches_window.rb', line 46

def build
  ensure! unless File.exist?(FILENAME)
  File.read(FILENAME)
end

.ensure!void

This method returns an undefined value.

Changelogger::Graph.ensure! -> void

Regenerates the graph cache file from the current repository.



20
21
22
23
24
25
26
27
28
# File 'lib/changelogger/branches_window.rb', line 20

def ensure!
  content = `git log --graph --decorate=short --date=short --pretty=format:'%h %d %s' 2>/dev/null`
  if content.nil? || content.strip.empty?
    content = "(no git graph available — empty repo or not a git repository)\n"
  end
  File.write(FILENAME, content)
rescue StandardError => e
  File.write(FILENAME, "(error generating graph: #{e.message})\n")
end

.widthInteger

Changelogger::Graph.width -> Integer

Returns the width of the widest graph line (used to size the pane).

Returns:

  • (Integer)


34
35
36
37
38
39
40
# File 'lib/changelogger/branches_window.rb', line 34

def width
  ensure! unless File.exist?(FILENAME)
  ensure!
  max = 1
  File.foreach(FILENAME) { |line| max = [max, line.rstrip.length].max }
  max
end