diff --git a/lib/software/internal/file.ex b/lib/software/internal/file.ex index 2b83253f..62dd34dc 100644 --- a/lib/software/internal/file.ex +++ b/lib/software/internal/file.ex @@ -1,7 +1,6 @@ defmodule Helix.Software.Internal.File do alias Helix.Software.Model.File - alias Helix.Software.Model.FileModule alias Helix.Software.Model.Storage alias Helix.Software.Repo @@ -121,7 +120,7 @@ defmodule Helix.Software.Internal.File do update(file, params) end - @spec encrypt(File.t, FileModule.version) :: + @spec encrypt(File.t, File.Module.version) :: {:ok, File.changeset} | {:error, File.changeset} def encrypt(file = %File{}, version) when version >= 1 do diff --git a/lib/software/model/file.ex b/lib/software/model/file.ex index 419cb156..51d66f70 100644 --- a/lib/software/model/file.ex +++ b/lib/software/model/file.ex @@ -8,9 +8,9 @@ defmodule Helix.Software.Model.File do alias Ecto.Changeset alias HELL.Constant - alias Helix.Software.Model.FileModule alias Helix.Software.Model.Software alias Helix.Software.Model.Storage + alias __MODULE__, as: File @type t :: t_of_type(Software.type) @@ -26,7 +26,7 @@ defmodule Helix.Software.Model.File do storage: term, inserted_at: NaiveDateTime.t, updated_at: NaiveDateTime.t, - modules: modules | FileModule.schema, + modules: modules | File.Module.schema, crypto_version: crypto_version } @@ -37,7 +37,7 @@ defmodule Helix.Software.Model.File do @type size :: pos_integer @type type :: Software.type @type crypto_version :: nil | pos_integer - @type modules :: FileModule.t + @type modules :: File.Module.t @type changeset :: %Changeset{data: %__MODULE__{}} @@ -49,7 +49,7 @@ defmodule Helix.Software.Model.File do storage_id: Storage.idtb } - @type module_params :: {FileModule.name, FileModule.Data.t} + @type module_params :: {File.Module.name, File.Module.Data.t} @type update_params :: %{ optional(:name) => name, @@ -88,7 +88,7 @@ defmodule Helix.Software.Model.File do references: :storage_id, define_field: false - has_many :modules, FileModule, + has_many :modules, File.Module, foreign_key: :file_id, references: :file_id, on_replace: :delete @@ -119,7 +119,7 @@ defmodule Helix.Software.Model.File do def format(file) do formatted_modules = Enum.reduce(file.modules, %{}, fn module, acc -> - module = FileModule.format(module) + module = File.Module.format(module) Map.merge(acc, module) end) @@ -158,9 +158,9 @@ defmodule Helix.Software.Model.File do end @spec create_module_assoc(module_params) :: - FileModule.changeset + File.Module.changeset docp """ - Helper/wrapper to `FileModule.create_changeset/1` + Helper/wrapper to `File.Module.create_changeset/1` """ defp create_module_assoc({name, data}) do params = %{ @@ -168,7 +168,7 @@ defmodule Helix.Software.Model.File do version: data.version } - FileModule.create_changeset(params) + File.Module.create_changeset(params) end docp """ @@ -251,13 +251,13 @@ defmodule Helix.Software.Model.File do do: where(query, [f], is_nil(f.crypto_version)) defp join_modules(query), - do: join(query, :left, [f], fm in FileModule, fm.file_id == f.file_id) + do: join(query, :left, [f], fm in File.Module, fm.file_id == f.file_id) defp join_assoc_modules(query), do: join(query, :left, [f], fm in assoc(f, :modules)) docp """ - Preloads FileModules into the schema + Preloads File.Modules into the schema """ defp preload_modules(query), do: preload(query, [..., m], [modules: m]) diff --git a/lib/software/model/file_module.ex b/lib/software/model/file/module.ex similarity index 85% rename from lib/software/model/file_module.ex rename to lib/software/model/file/module.ex index a69f86b2..4055e471 100644 --- a/lib/software/model/file_module.ex +++ b/lib/software/model/file/module.ex @@ -1,6 +1,6 @@ -defmodule Helix.Software.Model.FileModule do +defmodule Helix.Software.Model.File.Module do @moduledoc """ - A FileModule is a component of a File responsible for doing something. It + A File.Module is a component of a File responsible for doing something. It contains a version, which is a representation of how powerful that module is. For example, take the Cracker. It may have Overflow and Bruteforce modules. @@ -18,11 +18,11 @@ defmodule Helix.Software.Model.FileModule do alias Ecto.Changeset alias HELL.Constant alias Helix.Software.Model.File - alias Helix.Software.Model.FileModule.Data, as: FileModuleData alias Helix.Software.Model.Software + alias __MODULE__, as: Module @type t :: %{ - name => FileModuleData.t + name => Module.Data.t } @type schema :: %__MODULE__{ @@ -96,7 +96,7 @@ defmodule Helix.Software.Model.FileModule do Formats a FileModule """ def format(module = %__MODULE__{}) do - data = FileModuleData.new(module) + data = Module.Data.new(module) Map.put(%{}, module.name, data) end @@ -106,17 +106,17 @@ defmodule Helix.Software.Model.FileModule do FileModuleData contains information about the corresponding module. """ - alias Helix.Software.Model.FileModule + alias Helix.Software.Model.File @type t :: %__MODULE__{ - version: FileModule.version + version: File.Module.version } @enforce_keys [:version] defstruct [:version] - @spec new(FileModule.schema) :: + @spec new(File.Module.schema) :: t def new(%{version: version}) do %__MODULE__{ @@ -132,16 +132,15 @@ defmodule Helix.Software.Model.FileModule do alias Ecto.Queryable alias HELL.Constant alias Helix.Software.Model.File - alias Helix.Software.Model.FileModule @spec by_file(Queryable.t, File.idtb) :: Queryable.t - def by_file(query \\ FileModule, id), + def by_file(query \\ File.Module, id), do: where(query, [fm], fm.file_id == ^id) @spec by_name(Queryable.t, Constant.t) :: Queryable.t - def by_name(query \\ FileModule, name), + def by_name(query \\ File.Module, name), do: where(query, [fm], fm.name == ^name) end end diff --git a/lib/software/query/file.ex b/lib/software/query/file.ex index 09accdcd..ff5e5278 100644 --- a/lib/software/query/file.ex +++ b/lib/software/query/file.ex @@ -3,7 +3,6 @@ defmodule Helix.Software.Query.File do alias Helix.Cache.Query.Cache, as: CacheQuery alias Helix.Server.Model.Server alias Helix.Software.Model.File - alias Helix.Software.Model.FileModule alias Helix.Software.Model.Storage alias Helix.Software.Internal.File, as: FileInternal @@ -13,7 +12,7 @@ defmodule Helix.Software.Query.File do defdelegate fetch(file_id), to: FileInternal - @spec fetch_best(Server.id, FileModule.name) :: + @spec fetch_best(Server.id, File.Module.name) :: File.t | nil @doc """ @@ -28,7 +27,7 @@ defmodule Helix.Software.Query.File do fetch_best(List.first(storages), module) end - @spec fetch_best(Storage.t, FileModule.name) :: + @spec fetch_best(Storage.t, File.Module.name) :: File.t | nil @doc """ diff --git a/lib/software/software.ex b/lib/software/software.ex index 472f1a3b..c62b3ef7 100644 --- a/lib/software/software.ex +++ b/lib/software/software.ex @@ -51,7 +51,6 @@ defmodule Helix.Software do alias HELL.Constant alias Helix.Software.Model.File - alias Helix.Software.Model.FileModule @type t :: %{ type: type, @@ -65,7 +64,7 @@ defmodule Helix.Software do @type modules :: Constant.t @type extension :: File.extension - @type module_name :: FileModule.name + @type module_name :: File.Module.name @spec all :: [t] diff --git a/test/support/software/helper.ex b/test/support/software/helper.ex index 0f04e514..4fdf774f 100644 --- a/test/support/software/helper.ex +++ b/test/support/software/helper.ex @@ -2,7 +2,7 @@ defmodule Helix.Test.Software.Helper do alias Helix.Cache.Query.Cache, as: CacheQuery alias Helix.Server.Model.Server - alias Helix.Software.Model.FileModule + alias Helix.Software.Model.File alias Helix.Software.Model.Software alias Helix.Software.Model.Storage alias Helix.Software.Query.Storage, as: StorageQuery @@ -67,7 +67,7 @@ defmodule Helix.Test.Software.Helper do end defp generate_file_module(module, version) do - data = FileModule.Data.new(%{version: version}) + data = File.Module.Data.new(%{version: version}) Map.put(%{}, module, data) end