elixirmoney / money

Elixir library for working with Money safer, easier, and fun... Is an interpretation of the Fowler's Money pattern in fun.prog.
https://hex.pm/packages/money/
MIT License
827 stars 141 forks source link

Dynamically adding currency #165

Closed ErinHivelociy closed 3 years ago

ErinHivelociy commented 3 years ago

We are trying to use this in an application with custom currencies (point systems) and noticed if we would like to add a currency this requires adding to the config

config :money,
  custom_currencies: [
    BTC: %{name: "Bitcoin", symbol: "₿", exponent: 8},
    GCS: %{name: "Galactic Credit Standard", symbol: "gcs", exponent: 0}
  ]

Would be great if we could add currencies dynamically for example:

Money.Currency.add({BTC: %{name: "Bitcoin", symbol: "₿", exponent: 8})

Willing to help contribute with a PR if there is interest from package owners. Was thinking of using an :ets table to handle the currency definitions backed by a GenServer (for example). The biggest issue with this will be handling the dynamically created methods Money.Currency.#{currency}(100) Will need to find a way to maintain this behavior. 🤔

stevedomin commented 7 months ago

Hi @ErinHivelociy! Is there a way to do this in the library currently? If not, any reason why it was closed and would it still fit in the lib?