-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove some magic from handling categories files
- Loading branch information
1 parent
6d21ea1
commit 7c04591
Showing
9 changed files
with
67 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import Config | ||
|
||
config :ex_vision, cache_path: "models" |
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
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,39 @@ | ||
defmodule ExVision.Model.Definition.Parts.WithCategories do | ||
@moduledoc false | ||
require Logger | ||
alias ExVision.{Cache, Utils} | ||
|
||
defp get_categories(file) do | ||
file | ||
|> Cache.lazy_get() | ||
|> case do | ||
{:ok, file} -> | ||
Utils.load_categories(file) | ||
|
||
error -> | ||
Logger.error("Failed to load categories from #{file} due to #{inspect(error)}") | ||
raise "Failed to load categories from #{file}" | ||
end | ||
end | ||
|
||
defmacro __using__(options) do | ||
options = Keyword.validate!(options, [:name, :categories]) | ||
categories = options |> Keyword.fetch!(:categories) |> get_categories() | ||
spec = categories |> Enum.uniq() |> Bunch.Typespec.enum_to_alternative() | ||
|
||
quote do | ||
require Bunch.Typespec | ||
|
||
@typedoc """ | ||
Type describing all categories recognised by #{unquote(options[:name])} | ||
""" | ||
@type category_t() :: unquote(spec) | ||
|
||
@doc """ | ||
Returns a list of all categories recognised by #{unquote(options[:name])} | ||
""" | ||
@spec categories() :: [category_t()] | ||
def categories(), do: unquote(categories) | ||
end | ||
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