Composer.Ref (composer v0.2.0)

Copy Markdown View Source

A reference to a step or recipe: "cookbook:path".

iex> Composer.Ref.parse("composer_lab:ash/postgres")
{:ok, %Composer.Ref{cookbook: "composer_lab", path: "ash/postgres"}}

iex> Composer.Ref.parse("ash/postgres")
{:ok, %Composer.Ref{cookbook: nil, path: "ash/postgres"}}

A path is one or more /-separated segments of [a-z0-9_]. Input is normalized from - to _, so daisy-ui and daisy_ui are the same name. The hex: cookbook also accepts a private-repo package such as hex:oban.oban_pro.

Sources

A hex: reference may name where the package comes from, after an @, as mix igniter.install does:

iex> Composer.Ref.parse("hex:ash@3.5")
{:ok, %Composer.Ref{cookbook: "hex", path: "ash", source: [version: "~> 3.0"]}}

iex> Composer.Ref.parse("hex:my-lib@path:../my-lib")
{:ok, %Composer.Ref{cookbook: "hex", path: "my_lib", source: [path: "../my-lib"]}}
  • @<version> - @3.5.0 is "== 3.5.0", a partial version such as @3.5 is "~> 3.0" (Igniter's rule), and a requirement with an operator (@~>3.5) is kept as written
  • @github:owner/repo, or @github:owner/repo@ref
  • @git:<url>
  • @path:<path>

The reference is split on its first @, so the spec may contain :, @ and -; only the package name is normalized. A source is the same keyword list as the version:/github:/git:/path: options of a recipe entry (see Composer.Recipe). Any other reference with an @ is invalid.

Parsing never creates atoms.

Summary

Functions

True when path contains a /, i.e. it is grouped.

Joins a cookbook name and a path into a qualified reference string.

Parses a reference string.

Like parse/1, raising ArgumentError on an invalid reference.

True when package names a package in a private repo (org.pkg).

Formats a reference as cookbook:path, or path when unqualified, with its source in @ form.

Types

t()

@type t() :: %Composer.Ref{
  cookbook: String.t() | nil,
  path: String.t(),
  source: keyword()
}

Functions

grouped?(ref)

@spec grouped?(t()) :: boolean()

True when path contains a /, i.e. it is grouped.

id(cookbook, path)

@spec id(String.t(), String.t()) :: String.t()

Joins a cookbook name and a path into a qualified reference string.

parse(string)

@spec parse(String.t()) ::
  {:ok, t()} | {:error, {:invalid_ref, String.t(), String.t()}}

Parses a reference string.

parse!(string)

@spec parse!(String.t()) :: t()

Like parse/1, raising ArgumentError on an invalid reference.

repo_package?(package)

@spec repo_package?(String.t()) :: boolean()

True when package names a package in a private repo (org.pkg).

to_string(ref)

@spec to_string(t()) :: String.t()

Formats a reference as cookbook:path, or path when unqualified, with its source in @ form.