Class: Agentilda::Tree

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

Overview

A project's .plans directory: the folders in it, decoded and ordered.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir:) ⇒ Tree

Returns a new instance of Tree.

Parameters:

  • dir (String)

    the .plans directory



7
8
9
# File 'lib/agentilda/tree.rb', line 7

def initialize(dir:)
  @dir = File.expand_path(dir)
end

Instance Attribute Details

#dirString (readonly)

Returns absolute path to the .plans directory.

Returns:

  • (String)

    absolute path to the .plans directory



12
13
14
# File 'lib/agentilda/tree.rb', line 12

def dir
  @dir
end

Instance Method Details

#duplicatesHash{Agentilda::Ordinal => Array<String>}

Numbers claimed by more than one folder.

A plan's number is its identity: branch names, pull request titles and every pull-requests.md join on it. Two folders wearing the same number make every one of those joins ambiguous, and nothing downstream can tell which folder a [002.00] pull request belongs to.

Returns:



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

def duplicates
  features.group_by(&:ordinal)
    .select { |_, group| group.size > 1 }
    .transform_values { |group| group.map(&:dirname) }
end

#exist?Boolean

Returns:

  • (Boolean)


15
# File 'lib/agentilda/tree.rb', line 15

def exist? = File.directory?(dir)

#featuresArray<Agentilda::Feature>

Returns ordered by number.

Returns:



18
# File 'lib/agentilda/tree.rb', line 18

def features = @features ||= directories.filter_map { |p| Feature.parse(p) }.sort

#find(ordinal) ⇒ Agentilda::Subject?

Parameters:

Returns:



47
48
49
50
# File 'lib/agentilda/tree.rb', line 47

def find(ordinal)
  wanted = ordinal.is_a?(Ordinal) ? ordinal : Ordinal.parse(ordinal)
  subjects.find { |s| s.feature.ordinal == wanted }
end

#include?(ordinal) ⇒ Boolean

Returns whether a plan with this number exists on disk.

Returns:

  • (Boolean)

    whether a plan with this number exists on disk



53
# File 'lib/agentilda/tree.rb', line 53

def include?(ordinal) = !find(ordinal).nil?

#ordinalsArray<Agentilda::Ordinal>

Returns:



24
# File 'lib/agentilda/tree.rb', line 24

def ordinals = features.map(&:ordinal)

#reloadself

Forget everything read from disk, so a caller that has just renamed folders sees the new state.

Returns:

  • (self)


59
60
61
62
# File 'lib/agentilda/tree.rb', line 59

def reload
  @features = @subjects = @skipped = nil
  self
end

#skippedArray<String>

Directories that carry no plan number. Reported, never processed.

Returns:

  • (Array<String>)


29
# File 'lib/agentilda/tree.rb', line 29

def skipped = @skipped ||= directories.reject { |p| Feature.parse(p) }.map { |p| File.basename(p) }

#subjectsArray<Agentilda::Subject>

Returns ordered by number.

Returns:



21
# File 'lib/agentilda/tree.rb', line 21

def subjects = @subjects ||= features.map { |f| Subject.new(f) }