Class: Agentilda::Tree
- Inherits:
-
Object
- Object
- Agentilda::Tree
- Defined in:
- lib/agentilda/tree.rb
Overview
A project's .plans directory: the folders in it, decoded and ordered.
Instance Attribute Summary collapse
-
#dir ⇒ String
readonly
Absolute path to the
.plansdirectory.
Instance Method Summary collapse
-
#duplicates ⇒ Hash{Agentilda::Ordinal => Array<String>}
Numbers claimed by more than one folder.
- #exist? ⇒ Boolean
-
#features ⇒ Array<Agentilda::Feature>
Ordered by number.
- #find(ordinal) ⇒ Agentilda::Subject?
-
#include?(ordinal) ⇒ Boolean
Whether a plan with this number exists on disk.
-
#initialize(dir:) ⇒ Tree
constructor
A new instance of Tree.
- #ordinals ⇒ Array<Agentilda::Ordinal>
-
#reload ⇒ self
Forget everything read from disk, so a caller that has just renamed folders sees the new state.
-
#skipped ⇒ Array<String>
Directories that carry no plan number.
-
#subjects ⇒ Array<Agentilda::Subject>
Ordered by number.
Constructor Details
#initialize(dir:) ⇒ Tree
Returns a new instance of Tree.
7 8 9 |
# File 'lib/agentilda/tree.rb', line 7 def initialize(dir:) @dir = File.(dir) end |
Instance Attribute Details
#dir ⇒ String (readonly)
Returns absolute path to the .plans directory.
12 13 14 |
# File 'lib/agentilda/tree.rb', line 12 def dir @dir end |
Instance Method Details
#duplicates ⇒ Hash{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.
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
15 |
# File 'lib/agentilda/tree.rb', line 15 def exist? = File.directory?(dir) |
#features ⇒ Array<Agentilda::Feature>
Returns ordered by number.
18 |
# File 'lib/agentilda/tree.rb', line 18 def features = @features ||= directories.filter_map { |p| Feature.parse(p) }.sort |
#find(ordinal) ⇒ Agentilda::Subject?
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.
53 |
# File 'lib/agentilda/tree.rb', line 53 def include?(ordinal) = !find(ordinal).nil? |
#ordinals ⇒ Array<Agentilda::Ordinal>
24 |
# File 'lib/agentilda/tree.rb', line 24 def ordinals = features.map(&:ordinal) |
#reload ⇒ self
Forget everything read from disk, so a caller that has just renamed folders sees the new state.
59 60 61 62 |
# File 'lib/agentilda/tree.rb', line 59 def reload @features = @subjects = @skipped = nil self end |
#skipped ⇒ Array<String>
Directories that carry no plan number. Reported, never processed.
29 |
# File 'lib/agentilda/tree.rb', line 29 def skipped = @skipped ||= directories.reject { |p| Feature.parse(p) }.map { |p| File.basename(p) } |
#subjects ⇒ Array<Agentilda::Subject>
Returns ordered by number.
21 |
# File 'lib/agentilda/tree.rb', line 21 def subjects = @subjects ||= features.map { |f| Subject.new(f) } |