Class: Changelogger::Graph
- Inherits:
-
Object
- Object
- Changelogger::Graph
- Defined in:
- lib/changelogger/branches_window.rb
Overview
Changelogger::Graph caches ‘git log –graph` output for rendering.
Constant Summary collapse
- FILENAME =
Changelogger::Graph::FILENAMEstores the graph cache file name. '.graph'
Class Method Summary collapse
-
.build ⇒ String
Changelogger::Graph.build-> String. -
.ensure! ⇒ void
Changelogger::Graph.ensure!-> void. -
.width ⇒ Integer
Changelogger::Graph.width-> Integer.
Class Method Details
.build ⇒ String
Changelogger::Graph.build -> String
Reads the cached graph content (regenerates if missing).
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.})\n") end |
.width ⇒ Integer
Changelogger::Graph.width -> Integer
Returns the width of the widest graph line (used to size the pane).
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 |