-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converts Flippant to use a supervisor structure instead of being an application. Moving to a supervised structure allows us to completely move off of application config, and to application state using persistent term. Moving to persistent term forces an elixir version bump.
- Loading branch information
Showing
8 changed files
with
163 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule Flippant.Config do | ||
@moduledoc false | ||
|
||
@type t :: %__MODULE__{ | ||
adapter: module(), | ||
adapter_opts: Keyword.t(), | ||
name: module(), | ||
rules: module() | ||
} | ||
|
||
defstruct adapter: Flippant.Adapter.Memory, | ||
adapter_opts: [], | ||
name: Flippant, | ||
rules: Flippant.Rules.Default | ||
|
||
@spec new(Keyword.t()) :: t() | ||
def new(opts) when is_list(opts) do | ||
config = struct!(__MODULE__, opts) | ||
|
||
Map.update!(config, :adapter_opts, &default_adapter_opts(&1, config)) | ||
end | ||
|
||
@spec get(name :: atom()) :: t() | ||
def get(name), do: :persistent_term.get(name) | ||
|
||
@spec put(name :: atom(), config :: t()) :: :ok | ||
def put(name, %__MODULE__{} = conf) when is_atom(name), do: :persistent_term.put(name, conf) | ||
|
||
defp default_adapter_opts(opts, %{adapter: adapter}) do | ||
Keyword.put_new(opts, :name, adapter) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.