# `PhoenixMountable.Mount`
[🔗](https://github.com/hattoriai/phoenix_mountable/blob/v0.2.1/lib/phoenix_mountable/mount.ex#L1)

One mounted instance of a mountable library.

A host that calls a mount macro twice (for example an admin and a public
mount of the same library) gets two mounts, each with its own path and
options. The mount is available wherever the library's code runs:

  * in LiveViews, as `socket.assigns.mount` (and `@mount` in templates);
  * in controllers and plugs on the library's routes, as `conn.assigns.mount`
    and `conn.private.phoenix_mountable`;
  * anywhere in the process that handles the request or LiveView, through
    `current/0`.

## Fields

  * `:definition` — the library's definition module (the one that calls
    `use PhoenixMountable`)
  * `:name` — the mount name, the host's `:as` option
  * `:path` — the full mount path, including the host's enclosing scopes
  * `:router`, `:endpoint` — the host's router and endpoint (`:endpoint` is
    set at runtime)
  * `:options` — the library's options as given by the host, validated and
    with defaults, as a map
  * `:socket_path`, `:transport` — where and how the LiveView socket connects
  * `:csp_nonces` — the CSP nonces of the current request, by kind
    (`:script`, `:style`, ...), read from the host's assigns
  * `:asset_host` — an optional scheme and host for asset URLs (a CDN)
  * `:assets` — the asset strategy and its state
  * `:pubsub` — the PubSub server for `PhoenixMountable.PubSub`, if the host
    gave one; otherwise the endpoint's is used
  * `:session` — the library live session the current LiveView belongs to

# `t`

```elixir
@type t() :: %PhoenixMountable.Mount{
  asset_host: String.t() | nil,
  assets: {module(), term()} | nil,
  csp_nonce_assign_key: nil | atom() | map(),
  csp_nonces: map(),
  definition: module(),
  endpoint: module() | nil,
  host_on_mount: list(),
  name: atom(),
  options: map(),
  path: String.t(),
  pubsub: atom() | nil,
  router: module(),
  session: atom() | nil,
  socket_path: String.t(),
  transport: :websocket | :longpoll
}
```

# `current`

```elixir
@spec current() :: t() | nil
```

The mount of the current process: the LiveView or request being handled.

Set by PhoenixMountable when a library LiveView mounts and when a request
reaches a library route. Returns `nil` outside of them.

# `fetch`

```elixir
@spec fetch(map()) :: {:ok, t()} | :error
```

Returns `{:ok, mount}` for a socket, conn or assigns map, or `:error`.

# `fetch!`

```elixir
@spec fetch!(map()) :: t()
```

Returns the mount of a socket, conn or assigns map, raising if there is none.

# `key`

```elixir
@spec key(t()) :: {module(), atom()}
```

A key that identifies the mount on this node: `{router, name}`.

# `option`

```elixir
@spec option(t(), atom(), term()) :: term()
```

Returns the value of a library option.

# `sibling`

```elixir
@spec sibling(t() | map(), atom()) :: t() | nil
```

Another mount of the same router, by its name (the mount macro, or its
`:as`), from a mount, a conn, a socket or an assigns map. Returns `nil`
when the host has not mounted it.

A library with several definitions links from one to another with it:
its admin to its public page, say, wherever the host put the page.

    PhoenixMountable.Mount.sibling(conn, :my_lib_page)
    #=> %PhoenixMountable.Mount{name: :my_lib_page, path: "/changelog", ...}

See `PhoenixMountable.Path.path/3` for its paths.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
