Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Extra options:

App config can be used to set a global default to apply to all resources unless overridden in their individual config, or the LiveAdmin instance.

When set at the application level, resource-level keys are read at **compile time**, and must be configured in `config/config.exs` (or another compile-time config file). Setting any of them in `config/runtime.exs` (or otherwise at runtime) will raise on boot.
When set at the application level, resource-level keys are read at **compile time** via `Application.compile_env/2` and must be configured in `config/config.exs` (or another compile-time config file). Setting any of them in `config/runtime.exs` will cause Elixir to raise on boot due to the compile/runtime mismatch.

Compile-time keys: `components`, `query_with`, `render_with`, `delete_with`, `create_with`, `update_with`, `validate_with`, `label_with`, `title_with`, `hidden_fields`, `immutable_fields`, `actions`, `tasks`

Expand Down
2 changes: 1 addition & 1 deletion README.md.eex
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Extra options:

App config can be used to set a global default to apply to all resources unless overridden in their individual config, or the LiveAdmin instance.

When set at the application level, resource-level keys are read at **compile time**, and must be configured in `config/config.exs` (or another compile-time config file). Setting any of them in `config/runtime.exs` (or otherwise at runtime) will raise on boot.
When set at the application level, resource-level keys are read at **compile time** via `Application.compile_env/2` and must be configured in `config/config.exs` (or another compile-time config file). Setting any of them in `config/runtime.exs` will cause Elixir to raise on boot due to the compile/runtime mismatch.

Compile-time keys: `components`, `query_with`, `render_with`, `delete_with`, `create_with`, `update_with`, `validate_with`, `label_with`, `title_with`, `hidden_fields`, `immutable_fields`, `actions`, `tasks`

Expand Down
55 changes: 0 additions & 55 deletions lib/application.ex
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
defmodule LiveAdmin.Application do
use Application

@compile_time_app_keys [
:components,
:query_with,
:render_with,
:delete_with,
:create_with,
:update_with,
:validate_with,
:label_with,
:title_with,
:hidden_fields,
:immutable_fields,
:actions,
:tasks
]

@compile_time_app_config %{
components: Application.compile_env(:live_admin, :components),
query_with: Application.compile_env(:live_admin, :query_with),
render_with: Application.compile_env(:live_admin, :render_with),
delete_with: Application.compile_env(:live_admin, :delete_with),
create_with: Application.compile_env(:live_admin, :create_with),
update_with: Application.compile_env(:live_admin, :update_with),
validate_with: Application.compile_env(:live_admin, :validate_with),
label_with: Application.compile_env(:live_admin, :label_with),
title_with: Application.compile_env(:live_admin, :title_with),
hidden_fields: Application.compile_env(:live_admin, :hidden_fields),
immutable_fields: Application.compile_env(:live_admin, :immutable_fields),
actions: Application.compile_env(:live_admin, :actions),
tasks: Application.compile_env(:live_admin, :tasks)
}

def start(_type, _args) do
opts = [strategy: :one_for_one, name: LiveAdmin.Supervisor]

Expand All @@ -46,32 +14,9 @@ defmodule LiveAdmin.Application do

NimbleOptions.validate!(Application.get_all_env(:live_admin), global_options_schema)

validate_compile_time_config!()

Supervisor.start_link(children(), opts)
end

@doc false
def validate_compile_time_config! do
@compile_time_app_keys
|> Enum.filter(fn key ->
Map.fetch!(@compile_time_app_config, key) != Application.get_env(:live_admin, key)
end)
|> case do
[] ->
:ok

mismatches ->
raise """
The following :live_admin config keys have been set at runtime, but they must be set at compile time:

#{Enum.map_join(mismatches, "\n", &" * #{inspect(&1)}")}

Move these into config/config.exs (or another compile-time config file).
"""
end
end

defp children do
[
{LiveAdmin.Session.Agent, %{}},
Expand Down
2 changes: 1 addition & 1 deletion lib/live_admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ defmodule LiveAdmin do

Used internally to validate configuration in apps using LiveAdmin.

When set at the application level, every option in this schema *except* `ecto_repo` is read at compile time. Configure them in `config/config.exs` (or another compile-time config file); setting them at runtime will raise on boot.
When set at the application level, every option in this schema *except* `ecto_repo` is read at compile time via `Application.compile_env/2`. Configure them in `config/config.exs` (or another compile-time config file); setting them in `config/runtime.exs` will cause Elixir to raise on boot due to the compile/runtime mismatch.

Supported options:
#{@options_schema |> NimbleOptions.new!() |> NimbleOptions.docs()}
Expand Down
24 changes: 0 additions & 24 deletions test/live_admin/application_test.exs

This file was deleted.

Loading