Use NimbleOptions to validate MusicBrainz.Config
This commit is contained in:
@@ -7,9 +7,24 @@ defmodule MusicBrainz.Config do
|
||||
defstruct api: MusicBrainz.APIImpl,
|
||||
user_agent: "change me"
|
||||
|
||||
@schema NimbleOptions.new!(
|
||||
api: [
|
||||
type: :atom,
|
||||
required: true
|
||||
],
|
||||
user_agent: [
|
||||
type: :string,
|
||||
required: false,
|
||||
default: "change me"
|
||||
]
|
||||
)
|
||||
|
||||
@doc NimbleOptions.docs(@schema)
|
||||
@spec resolve(atom) :: t
|
||||
def resolve(otp_app) do
|
||||
app_config = Application.get_env(otp_app, MusicBrainz)
|
||||
app_config =
|
||||
Application.get_env(otp_app, MusicBrainz)
|
||||
|> NimbleOptions.validate!(@schema)
|
||||
|
||||
struct(__MODULE__, app_config)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user