Money.Currency.Store (Money v6.0.0-rc.0)

Copy Markdown View Source

Persistent-term-backed store for custom currencies.

Custom currencies are currencies defined at runtime using Money.Currency.new/2. They are stored in :persistent_term for fast concurrent read access.

This module is started as part of the Money application supervision tree.

Summary

Functions

Returns all custom currencies as a map of %{currency_code => currency_struct}.

Returns a specification to start this module under a supervisor.

Returns a list of all custom currency codes.

Returns the custom currency for the given code, or nil.

Stores a custom currency.

Starts the custom currency store.

Functions

all()

@spec all() :: %{required(atom()) => Localize.Currency.t()}

Returns all custom currencies as a map of %{currency_code => currency_struct}.

Returns

  • A map of custom currencies. Returns an empty map if no custom currencies have been defined.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

codes()

@spec codes() :: [atom()]

Returns a list of all custom currency codes.

Returns

  • A list of atom currency codes.

get(code)

@spec get(atom()) :: Localize.Currency.t() | nil

Returns the custom currency for the given code, or nil.

Arguments

  • code is a currency code atom.

Returns

put(currency)

@spec put(Localize.Currency.t()) ::
  {:ok, Localize.Currency.t()} | {:error, Exception.t()}

Stores a custom currency.

Arguments

Returns

  • {:ok, currency} on success.

  • {:error, Money.CurrencyNotSavedError.t()} if the store is not running.

start_link(options \\ [])

Starts the custom currency store.