Packages
Watch and fetch application's configuration from a server, and compile them into Elixir modules.
Current section
13 Versions
Jump to
Current section
13 Versions
Compare versions
8
files changed
+46
additions
-25
deletions
| @@ -5,8 +5,9 @@ | |
| 5 5 | {<<"elixir">>,<<">= 1.12.0">>}. |
| 6 6 | {<<"files">>, |
| 7 7 | [<<"lib">>,<<"lib/formular">>,<<"lib/formular/client">>, |
| 8 | - <<"lib/formular/client/supervisor.ex">>,<<"lib/formular/client/mock.ex">>, |
| 8 | + <<"lib/formular/client/supervisor.ex">>, |
| 9 9 | <<"lib/formular/client/listener.ex">>,<<"lib/formular/client/adapter">>, |
| 10 | + <<"lib/formular/client/adapter/mock.ex">>, |
| 10 11 | <<"lib/formular/client/adapter/websocket.ex">>, |
| 11 12 | <<"lib/formular/client/cache.ex">>,<<"lib/formular/client/compiler.ex">>, |
| 12 13 | <<"lib/formular/client/config.ex">>, |
| @@ -36,4 +37,4 @@ | |
| 36 37 | {<<"optional">>,false}, |
| 37 38 | {<<"repository">>,<<"hexpm">>}, |
| 38 39 | {<<"requirement">>,<<"~> 0.3.1">>}]]}. |
| 39 | - {<<"version">>,<<"0.2.0-alpha.1">>}. |
| 40 | + {<<"version">>,<<"0.2.0">>}. |
| @@ -0,0 +1,25 @@ | |
| 1 | + defmodule Formular.Client.Adapter.Mock do |
| 2 | + alias Formular.Client.Cache |
| 3 | + |
| 4 | + def start_link(_config, opts) do |
| 5 | + {:ok, pid} = Agent.start_link(fn -> :ok end) |
| 6 | + |
| 7 | + case opts[:formulas] do |
| 8 | + formulas when is_list(formulas) -> |
| 9 | + Enum.each(formulas, fn {name, function} -> |
| 10 | + mock_global(name, function) |
| 11 | + end) |
| 12 | + |
| 13 | + nil -> |
| 14 | + :ok |
| 15 | + end |
| 16 | + |
| 17 | + {:ok, pid} |
| 18 | + end |
| 19 | + |
| 20 | + def mock_global(name, function) |
| 21 | + when is_binary(function) |
| 22 | + when is_function(function, 2) do |
| 23 | + Cache.put(name, function) |
| 24 | + end |
| 25 | + end |
| @@ -7,7 +7,7 @@ defmodule Formular.Client.Adapter.Websocket do | |
| 7 7 | |
| 8 8 | require Logger |
| 9 9 | |
| 10 | - def start_link(%Config{} = config) do |
| 10 | + def start_link(%Config{} = config, _options) do |
| 11 11 | Logger.debug(["Starting new formula websocket client, ", inspect(config)]) |
| 12 12 | |
| 13 13 | GenSocketClient.start_link( |
| @@ -5,7 +5,7 @@ defmodule Formular.Client.Application do | |
| 5 5 | children = [ |
| 6 6 | Formular.Client.Compiler, |
| 7 7 | Formular.Client.Cache, |
| 8 | - {DynamicSupervisor, name: Formular.Client.Sockets, strategy: :one_for_one} |
| 8 | + {DynamicSupervisor, name: Formular.Client.Instances, strategy: :one_for_one} |
| 9 9 | ] |
| 10 10 | |
| 11 11 | Supervisor.start_link(children, strategy: :one_for_all) |
| @@ -14,7 +14,7 @@ defmodule Formular.Client.Config do | |
| 14 14 | url: String.t(), |
| 15 15 | formulas: [formula_def()], |
| 16 16 | compiler: {module(), atom(), args :: list()} | compile_function(), |
| 17 | - adapter: module() |
| 17 | + adapter: {module(), keyword()} |
| 18 18 | } |
| 19 19 | |
| 20 20 | defstruct [ |
| @@ -22,7 +22,7 @@ defmodule Formular.Client.Config do | |
| 22 22 | :url, |
| 23 23 | :formulas, |
| 24 24 | compiler: {Formular.Client.Compiler, :compile, []}, |
| 25 | - adapter: Formular.Client.Adapter.Websocket |
| 25 | + adapter: {Formular.Client.Adapter.Websocket, []} |
| 26 26 | ] |
| 27 27 | |
| 28 28 | @doc """ |
| @@ -30,7 +30,7 @@ defmodule Formular.Client.Config do | |
| 30 30 | """ |
| 31 31 | @spec new(Enum.t()) :: t() |
| 32 32 | def new(opts) do |
| 33 | - struct!(Config, opts |> IO.inspect(label: "opts")) |
| 33 | + struct!(Config, opts) |
| 34 34 | |> format_formulas() |
| 35 35 | end |
Loading more files…