# Class LittleGhost::Support::Loader

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Support/Loader.html

Loader finds agents, assemblies, and tools from a conventional application
layout. Ruby files map to constants by path, so applications can add extension
classes without maintaining a manual require list.

    loader = LittleGhost::Support::Loader.new(root: Dir.pwd)
    loader.setup.eager_load

Setup is process-serialized, collisions are rejected, and real paths are
checked for symbolic-link escapes. Application load roots are trusted code,
not a sandbox for untrusted files.

## Inheritance

`LittleGhost::Support::Loader < Object`

## Attributes

<a id="attribute-i-directories"></a>
### `directories` (R)

Application root and configured relative load directories.

<a id="attribute-i-root"></a>
### `root` (R)

Application root and configured relative load directories.

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(paths: nil, root: nil, directories: DEFAULT_DIRECTORIES)
```

Uses explicit `paths` or conventional directories beneath `root`.

## Instance methods

<a id="method-i-constant"></a>
### `#constant`

```ruby
#constant(name)
```

Loads an application constant after installing autoloads.

<a id="method-i-eager_load"></a>
### `#eager_load`

```ruby
#eager_load()
```

Loads every registered constant and verifies its defining file.

<a id="method-i-fetch"></a>
### `#fetch`

```ruby
#fetch(relative_path)
```

Finds a relative file or raises LoadError.

<a id="method-i-find"></a>
### `#find`

```ruby
#find(relative_path)
```

Finds a relative file beneath configured paths, returning its resolved path or
nil.

<a id="method-i-glob"></a>
### `#glob`

```ruby
#glob(pattern)
```

Finds resolved paths matching a relative glob without root escapes.

<a id="method-i-loaded_constant-3F"></a>
### `#loaded_constant?`

```ruby
#loaded_constant?(name)
```

Checks whether `name` was loaded from its registered source path.

<a id="method-i-read"></a>
### `#read`

```ruby
#read(relative_path, encoding: "UTF-8")
```

Reads a relative file using `encoding`.

<a id="method-i-registered_constants"></a>
### `#registered_constants`

```ruby
#registered_constants()
```

Copies registered constant names and resolved paths.

<a id="method-i-setup"></a>
### `#setup`

```ruby
#setup()
```

Installs autoloads for the current registry and returns self.
