Class: Agentilda::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/agentilda/index.rb

Overview

agentilda index — the project's plans as one browsable page.

Reporter answers "what is the state of things" in a terminal, in columns, for someone standing at a prompt. This answers "what is this project, and where is everything" for someone arriving at the repository on the web: the goal of each plan in its own words, every pull request as a link, and every document in the folder one click away.

It is generated for the same reason the conventions document is. A hand-written index of twenty plans cannot survive a rename, and renaming is exactly what resync dirs exists to do — the first hand-made INDEX.md this replaced had all 82 of its links pointing at folder names that had been padded to NNN.MM underneath it.

Constant Summary collapse

FILENAME =

The file this writes, relative to the .plans directory.

"INDEX.md"
ARTIFACT_NAMES =

Documents that get a proper name rather than their filename.

{
  "spec.md" => "Spec",
  "plan.md" => "Plan",
  "pull-requests.md" => "Pull Requests",
  "linear.md" => "Linear",
  "blocked.md" => "Blocked",
  "delayed.md" => "Deferred",
  "rewrite.md" => "Rewrite",
  "deployed.md" => "Deployed",
  "rollback.md" => "Rollback",
  "discarded.md" => "Discarded"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree:, project: nil) ⇒ Index

Returns a new instance of Index.

Parameters:

  • tree (Agentilda::Tree)
  • project (String, nil) (defaults to: nil)

    the heading; defaults to the repository name



40
41
42
43
# File 'lib/agentilda/index.rb', line 40

def initialize(tree:, project: nil)
  @tree = tree
  @project = project
end

Instance Attribute Details

#treeAgentilda::Tree (readonly)

Returns:



46
47
48
# File 'lib/agentilda/index.rb', line 46

def tree
  @tree
end

Instance Method Details

#projectString

Returns the project's name, titleized from its directory.

Returns:

  • (String)

    the project's name, titleized from its directory



49
# File 'lib/agentilda/index.rb', line 49

def project = @project ||= Agentilda.titleize(File.basename(File.dirname(tree.dir)))

#renderString

Returns the whole document.

Returns:

  • (String)

    the whole document



52
53
54
# File 'lib/agentilda/index.rb', line 52

def render
  [heading, *tree.subjects.map { |subject| section(subject) }].join("\n") + footer
end

#write(path = nil) ⇒ String

Write it next to the plans it describes.

Parameters:

  • path (String, nil) (defaults to: nil)

    override the destination

Returns:

  • (String)

    where it was written



60
61
62
63
64
# File 'lib/agentilda/index.rb', line 60

def write(path = nil)
  path ||= File.join(tree.dir, FILENAME)
  File.write(path, render)
  path
end