Packmatic.Manifest (Packmatic v1.1.2) View Source

Represents the customer’s request for a particular compressed file.

The Manifest is constructed with a list of Packmatic.Manifest.Entry structs, which each represents one file to be placed into the Package. Entries are validated when they are added to the Manifest.

Creating Manifests

Manifests can be created iteratively by calling prepend/2 against an existing Manifest, or by calling create/1 with a list of Entries created elsewhere.

Calling create/0 provides you with an empty Manifest which is not valid:

iex(1)> Packmatic.Manifest.create()
%Packmatic.Manifest{entries: [], errors: [manifest: :empty], valid?: false}

However, prepending valid Entries makes it valid:

iex(1)> manifest = Packmatic.Manifest.create()
iex(2)> manifest = Packmatic.Manifest.prepend(manifest, source: {:random, 1}, path: "foo")
iex(3)> manifest.valid?
true

Creating a Manifest from a list of Entries also results in a valid Manifest:

iex(1)> manifest = Packmatic.Manifest.create([[source: {:random, 1}, path: "foo"]])
iex(2)> manifest.valid?
true

Validity and Error Reporting

An empty Manifest is not valid because the result is not useful. It contains a Manifest-level error {:manifest, :empty}.

iex(1)> manifest = Packmatic.Manifest.create()
iex(2)> manifest.errors
[manifest: :empty]

If an Entry is not valid when appended to a Manifest, it will make the Manifest invalid and a corresponding error entry will also be added to the :errors key.

Since entries are prepended to the list, Entry-level errors are emitted with a negative index (counted from the tail of the list). So the last item (first to be appended) has the index of -1, the penultimate item has the index of -2, and so on.

iex(1)> manifest = Packmatic.Manifest.create()
iex(2)> manifest = Packmatic.Manifest.prepend(manifest, source: {:file, nil})
iex(3)> manifest.errors
[{{:entry, -1}, [source: :invalid, path: :missing]}]

Entry-level errors are emitted per key, and defined under Packmatic.Manifest.Entry.error/0.

Link to this section Summary

Types

Represents an Error which can be related to an Entry or the Manifest itself.

Represents an Error regarding an Entry. Index is negative, counted from tail.

Represents an Error with the Manifest.

Represents an error condition where the Manifest has no entries.

Represents an invalid Manifest, where there must be errors and might be Entries.

t()

Represents the Manifest.

Represents a valid Manifest, where there must be Entries and no errors.

Functions

Creates a Manifest based on Entries given. If there are no Entries, the Manifest will be invalid by default. Otherwise, each Entry will be validated and the Manifest will remain valid if all Entries provided were valid.

Prepends the given Entry to the Manifest. If the Entry is invalid, the Manifest will also become invalid, and the error will be prepended to the list.

Link to this section Types

Specs

error() :: error_entry() | error_manifest()

Represents an Error which can be related to an Entry or the Manifest itself.

Specs

error_entry() :: {{:entry, neg_integer()}, Packmatic.Manifest.Entry.error()}

Represents an Error regarding an Entry. Index is negative, counted from tail.

Specs

error_manifest() :: {:manifest, error_manifest_reason()}

Represents an Error with the Manifest.

Link to this type

error_manifest_reason()

View Source

Specs

error_manifest_reason() :: :empty

Represents an error condition where the Manifest has no entries.

Specs

invalid() :: %Packmatic.Manifest{
  entries: [Packmatic.Manifest.Entry.t()],
  errors: [error(), ...],
  valid?: false
}

Represents an invalid Manifest, where there must be errors and might be Entries.

Specs

t() :: %Packmatic.Manifest{
  entries: [Packmatic.Manifest.Entry.t()],
  errors: [error()],
  valid?: true | false
}

Represents the Manifest.

Specs

valid() :: %Packmatic.Manifest{
  entries: [Packmatic.Manifest.Entry.t(), ...],
  errors: [],
  valid?: true
}

Represents a valid Manifest, where there must be Entries and no errors.

Link to this section Functions

Specs

create([]) :: invalid()
create([Packmatic.Manifest.Entry.t() | Packmatic.Manifest.Entry.proplist(), ...]) ::
  valid() | invalid()

Creates a Manifest based on Entries given. If there are no Entries, the Manifest will be invalid by default. Otherwise, each Entry will be validated and the Manifest will remain valid if all Entries provided were valid.

Specs

Prepends the given Entry to the Manifest. If the Entry is invalid, the Manifest will also become invalid, and the error will be prepended to the list.