Skip to content

Commit

Permalink
Simplify implementation of config validator
Browse files Browse the repository at this point in the history
  • Loading branch information
tlux committed May 10, 2019
1 parent 0ef9acb commit 8ba50b2
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/sftp_client/operations/connect.ex
Expand Up @@ -100,22 +100,19 @@ defmodule SFTPClient.Operations.Connect do
defp validate_config(config) do
config
|> Map.from_struct()
|> Enum.find_value(:ok, fn
{_key, nil} ->
nil

{key, value} ->
case validate_config_value(key, value) do
:ok ->
nil

{:error, reason} ->
{:error,
%InvalidOptionError{key: key, value: value, reason: reason}}
end
|> Enum.find_value(:ok, fn {key, value} ->
case validate_config_value(key, value) do
:ok ->
nil

{:error, reason} ->
{:error, %InvalidOptionError{key: key, value: value, reason: reason}}
end
end)
end

defp validate_config_value(_key, nil), do: :ok

defp validate_config_value(:private_key_path, path) do
if File.exists?(Path.expand(path)) do
:ok
Expand Down

0 comments on commit 8ba50b2

Please sign in to comment.