-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move mix and escript examples module to an external dir * add supported types config * accumulate commands attr * improve cmd parsing and create exceptions
- Loading branch information
Showing
8 changed files
with
65 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Config | ||
|
||
config :nexus, supported_types: ~w(string atom integer float)a |
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defmodule Nexus.Command.MissingType do | ||
defexception message: "Command type is missing" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule Nexus.Command.NotSupportedType do | ||
defexception [:message] | ||
|
||
@impl true | ||
def exception(type) do | ||
%__MODULE__{message: "Command type not supported yet: #{inspect(type)}"} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule Nexus.Command.Validation do | ||
@moduledoc """ | ||
Defines validations for a `Nexus.Command` struct | ||
""" | ||
|
||
alias Nexus.Command.MissingType | ||
alias Nexus.Command.NotSupportedType | ||
|
||
@supported_types Application.compile_env!(:nexus, :supported_types) | ||
|
||
@spec validate_type(map) :: map | ||
def validate_type(%{type: type} = attrs) do | ||
if type in @supported_types do | ||
attrs | ||
else | ||
raise NotSupportedType, type | ||
end | ||
end | ||
|
||
def validate_type(_), do: raise(MissingType) | ||
|
||
@spec validate_name(map) :: map | ||
def validate_name(%{name: name} = attrs) do | ||
if is_atom(name) do | ||
attrs | ||
else | ||
raise ArgumentError, "Command name must be an atom" | ||
end | ||
end | ||
end |