Skip to content

Commit

Permalink
Add doctest formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen committed Jul 18, 2024
1 parent a2275ff commit 73408be
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
plugins: [Styler],
plugins: [DoctestFormatter, Styler],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
3 changes: 2 additions & 1 deletion lib/senzing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule Senzing do
@doc false
@spec locate_root_path() :: Path.t()
def locate_root_path do
path = System.get_env("SENZING_ROOT", Application.get_env(:senzing, :root_path, "/opt/senzing"))
path =
System.get_env("SENZING_ROOT", Application.get_env(:senzing, :root_path, "/opt/senzing"))

unless File.exists?(Path.join(path, "data")) do
raise """
Expand Down
59 changes: 36 additions & 23 deletions lib/senzing/g2/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ defmodule Senzing.G2.Config do
def handle_call({:add_data_source, data_source}, _from, config) do
{:reply,
with(
{:ok, response} <- Nif.add_data_source(config, IO.iodata_to_binary(:json.encode(data_source))),
{:ok, response} <-
Nif.add_data_source(config, IO.iodata_to_binary(:json.encode(data_source))),
do: {:ok, :json.decode(response)}
), config}
end
Expand Down Expand Up @@ -149,8 +150,8 @@ defmodule Senzing.G2.Config do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, _json} = Senzing.G2.Config.save(config)
iex> # {:ok, "{\"G2_CONFIG\": \"...\"}"}
...> {:ok, _json} = Senzing.G2.Config.save(config)
...> # {:ok, "{\"G2_CONFIG\": \"...\"}"}
"""
@doc type: :configuration_object_management
Expand All @@ -165,11 +166,12 @@ defmodule Senzing.G2.Config do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, _data_sources} = Senzing.G2.Config.list_data_sources(config)
{:ok, [
%{"DSRC_CODE" => "TEST", "DSRC_ID" => 1},
%{"DSRC_CODE" => "SEARCH", "DSRC_ID" => 2}
]}
...> {:ok, _data_sources} = Senzing.G2.Config.list_data_sources(config)
{:ok,
[
%{"DSRC_CODE" => "TEST", "DSRC_ID" => 1},
%{"DSRC_CODE" => "SEARCH", "DSRC_ID" => 2}
]}
"""
@doc type: :datasource_management
Expand All @@ -184,13 +186,17 @@ defmodule Senzing.G2.Config do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, _data_source} = Senzing.G2.Config.add_data_source(config, %{"DSRC_CODE" => "NAME_OF_DATASOURCE"})
iex> {:ok, _data_sources} = Senzing.G2.Config.list_data_sources(config)
{:ok, [
%{"DSRC_CODE" => "TEST", "DSRC_ID" => 1},
%{"DSRC_CODE" => "SEARCH", "DSRC_ID" => 2},
%{"DSRC_CODE" => "NAME_OF_DATASOURCE", "DSRC_ID" => 1001}
]}
...>
...> {:ok, _data_source} =
...> Senzing.G2.Config.add_data_source(config, %{"DSRC_CODE" => "NAME_OF_DATASOURCE"})
...>
...> {:ok, _data_sources} = Senzing.G2.Config.list_data_sources(config)
{:ok,
[
%{"DSRC_CODE" => "TEST", "DSRC_ID" => 1},
%{"DSRC_CODE" => "SEARCH", "DSRC_ID" => 2},
%{"DSRC_CODE" => "NAME_OF_DATASOURCE", "DSRC_ID" => 1001}
]}
"""
@doc type: :datasource_management
Expand All @@ -206,16 +212,23 @@ defmodule Senzing.G2.Config do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, _data_source} = Senzing.G2.Config.add_data_source(config, %{"DSRC_CODE" => "NAME_OF_DATASOURCE"})
iex> :ok = Senzing.G2.Config.delete_data_source(config, %{"DSRC_CODE" => "NAME_OF_DATASOURCE"})
iex> {:ok, _data_sources} = Senzing.G2.Config.list_data_sources(config)
{:ok, [
%{"DSRC_CODE" => "TEST", "DSRC_ID" => 1},
%{"DSRC_CODE" => "SEARCH", "DSRC_ID" => 2}
]}
...>
...> {:ok, _data_source} =
...> Senzing.G2.Config.add_data_source(config, %{"DSRC_CODE" => "NAME_OF_DATASOURCE"})
...>
...> :ok =
...> Senzing.G2.Config.delete_data_source(config, %{"DSRC_CODE" => "NAME_OF_DATASOURCE"})
...>
...> {:ok, _data_sources} = Senzing.G2.Config.list_data_sources(config)
{:ok,
[
%{"DSRC_CODE" => "TEST", "DSRC_ID" => 1},
%{"DSRC_CODE" => "SEARCH", "DSRC_ID" => 2}
]}
"""
@doc type: :datasource_management
@spec delete_data_source(server :: GenServer.server(), data_source :: data_source()) :: G2.result()
@spec delete_data_source(server :: GenServer.server(), data_source :: data_source()) ::
G2.result()
def delete_data_source(server, data_source), do: GenServer.call(server, {:delete_data_source, data_source})
end
49 changes: 27 additions & 22 deletions lib/senzing/g2/config_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ defmodule Senzing.G2.ConfigManager do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, config_json} = Senzing.G2.Config.save(config)
iex> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
iex> is_integer(config_id)
...> {:ok, config_json} = Senzing.G2.Config.save(config)
...> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
...> is_integer(config_id)
true
"""
Expand All @@ -78,10 +78,10 @@ defmodule Senzing.G2.ConfigManager do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, config_json} = Senzing.G2.Config.save(config)
iex> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
iex> {:ok, config_json} = Senzing.G2.ConfigManager.get_config(config_id)
iex> is_binary(config_json)
...> {:ok, config_json} = Senzing.G2.Config.save(config)
...> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
...> {:ok, config_json} = Senzing.G2.ConfigManager.get_config(config_id)
...> is_binary(config_json)
true
"""
Expand All @@ -96,7 +96,8 @@ defmodule Senzing.G2.ConfigManager do
## Examples
iex> {:ok, configs} = Senzing.G2.ConfigManager.list_configs()
iex> # {:ok, [%{"CONFIG_COMMENTS" => "comment", "CONFIG_ID" => 1990907876, "SYS_CREATE_DT" => "2024-02-22 19:46:22.556"}]}
...>
...> # {:ok, [%{"CONFIG_COMMENTS" => "comment", "CONFIG_ID" => 1990907876, "SYS_CREATE_DT" => "2024-02-22 19:46:22.556"}]}
"""
@spec list_configs() :: G2.result([config_parameters()])
Expand All @@ -114,7 +115,7 @@ defmodule Senzing.G2.ConfigManager do
## Examples
iex> {:ok, default_config_id} = Senzing.G2.ConfigManager.get_default_config_id()
iex> is_integer(default_config_id)
...> is_integer(default_config_id)
true
"""
Expand All @@ -129,11 +130,11 @@ defmodule Senzing.G2.ConfigManager do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, config_json} = Senzing.G2.Config.save(config)
iex> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
iex> :ok = Senzing.G2.ConfigManager.set_default_config_id(config_id)
iex> {:ok, default_config_id} = Senzing.G2.ConfigManager.get_default_config_id()
iex> config_id == default_config_id
...> {:ok, config_json} = Senzing.G2.Config.save(config)
...> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
...> :ok = Senzing.G2.ConfigManager.set_default_config_id(config_id)
...> {:ok, default_config_id} = Senzing.G2.ConfigManager.get_default_config_id()
...> config_id == default_config_id
true
"""
Expand All @@ -148,16 +149,20 @@ defmodule Senzing.G2.ConfigManager do
## Examples
iex> {:ok, config} = Senzing.G2.Config.start_link([])
iex> {:ok, config_json} = Senzing.G2.Config.save(config)
iex> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
iex> :ok = Senzing.G2.ConfigManager.set_default_config_id(config_id)
iex> {:ok, new_config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
iex> :ok = Senzing.G2.ConfigManager.replace_default_config_id(new_config_id, config_id)
iex> {:ok, default_config_id} = Senzing.G2.ConfigManager.get_default_config_id()
iex> new_config_id == default_config_id
...> {:ok, config_json} = Senzing.G2.Config.save(config)
...> {:ok, config_id} = Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
...> :ok = Senzing.G2.ConfigManager.set_default_config_id(config_id)
...>
...> {:ok, new_config_id} =
...> Senzing.G2.ConfigManager.add_config(config_json, comment: "comment")
...>
...> :ok = Senzing.G2.ConfigManager.replace_default_config_id(new_config_id, config_id)
...> {:ok, default_config_id} = Senzing.G2.ConfigManager.get_default_config_id()
...> new_config_id == default_config_id
true
"""
@spec replace_default_config_id(new_config_id :: config_id(), old_config_id :: config_id()) :: G2.result()
@spec replace_default_config_id(new_config_id :: config_id(), old_config_id :: config_id()) ::
G2.result()
defdelegate replace_default_config_id(new_config_id, old_config_id), to: Nif
end
Loading

0 comments on commit 73408be

Please sign in to comment.