Class: RailsHttpLab::Storage::Tree

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

Overview

Builds a hierarchical view of the storage root for the sidebar. Returns:

{
  name: "My APIs",
  type: "collection",
  children: [
    { type: "folder", name: "...", path: "...", children: [...] },
    { type: "request", name: "...", path: "...", method: "GET", seq: 1 }
  ],
  environments: [{ name: "Local", path: "environments/Local.bru" }]
}

Instance Method Summary collapse

Constructor Details

#initialize(root: RailsHttpLab.config.resolved_storage_path) ⇒ Tree

Returns a new instance of Tree.



17
18
19
# File 'lib/rails_http_lab/storage/tree.rb', line 17

def initialize(root: RailsHttpLab.config.resolved_storage_path)
  @root = Pathname.new(root.to_s)
end

Instance Method Details

#buildObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_http_lab/storage/tree.rb', line 21

def build
  return empty_tree unless @root.directory?

  collection = read_collection_manifest
  children   = list_children(@root, relative_prefix: "")
  envs       = list_environments

  {
    name:         collection["name"] || @root.basename.to_s,
    type:         "collection",
    children:     children,
    environments: envs
  }
end