Skip to content
Kward Search API index

Class: Kward::PromptInterface::ProjectFileTree

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/prompt_interface/project_file_tree.rb

Overview

The filesystem-independent tree shared by /files and the editor Explorer.

Instance Method Summary collapse

Constructor Details

#initialize(paths, directories: []) ⇒ ProjectFileTree

Returns a new instance of ProjectFileTree.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kward/prompt_interface/project_file_tree.rb', line 7

def initialize(paths, directories: [])
  @directories = Hash.new { |hash, key| hash[key] = Set.new }
  @files = Hash.new { |hash, key| hash[key] = [] }
  directories.each { |path| add_directories(path.split("/")) }
  paths.each do |path|
    parent = add_directories(path.split("/")[0...-1])
    @files[parent] << path
  end
  @directories.transform_values! { |children| children.to_a.sort }
  @files.each_value(&:sort!)
end

Instance Method Details

#rows(expanded) ⇒ Object



19
20
21
# File 'lib/kward/prompt_interface/project_file_tree.rb', line 19

def rows(expanded)
  append_rows([], "", expanded, 0)
end