Skip to content

Commit 1241296

Browse files
committed
Add queue validate derive, mnesia starter helper
1 parent d64a833 commit 1241296

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/macros/guarded_struct/derive/validation_derive.ex

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ defmodule MishkaDeveloperTools.Macros.GuardedStruct.Derive.ValidationDerive do
153153
end
154154
end
155155

156+
def validate(:queue, input, field) do
157+
if QueueAssistant.is_queue?(input) do
158+
input
159+
else
160+
{:error, field, :queue, "The #{field} field must be a queue format"}
161+
end
162+
end
163+
156164
def validate({:max_len, len}, input, field) when is_binary(input) do
157165
if String.length(input) <= len,
158166
do: input,

lib/modules/mnesia_assistant/mnesia_assistant.ex

+13
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ defmodule MnesiaAssistant do
1515
6. `MnesiaAssistant.BackupAndRestore`
1616
"""
1717

18+
require Logger
1819
alias MnesiaAssistant.{Information, Schema}
1920
alias MishkaDeveloperTools.Helper.Extra
21+
alias MnesiaAssistant.Error, as: MError
2022
alias :mnesia, as: Mnesia
2123

2224
################################################################
@@ -54,6 +56,17 @@ defmodule MnesiaAssistant do
5456
"""
5557
def start(:app), do: Application.start(:mnesia)
5658

59+
@doc false
60+
def start(mode, dir, identifier) do
61+
Logger.warning("Mnesia's initial valuation process has begun.")
62+
stop() |> MError.error_description()
63+
mnesia_dir = dir <> "/#{mode}"
64+
File.mkdir_p(mnesia_dir) |> MError.error_description(identifier)
65+
Application.put_env(:mnesia, :dir, mnesia_dir |> to_charlist)
66+
MnesiaAssistant.Schema.create_schema([node()]) |> MError.error_description(identifier)
67+
start() |> MError.error_description(identifier)
68+
end
69+
5770
@doc """
5871
The `mnesia` database provides you with the capability to perform your storage
5972
either on the hard drive or on the RAM, or both at the same time, depending

lib/modules/queue_assistant.ex

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule QueueAssistant do
22
@moduledoc """
33
This is a simple wrapper for the Erlang queue, in which the order of some entries
44
has also been changed
5+
6+
- **Based on:** https://www.erlang.org/doc/man/queue
57
"""
68

79
@type queue_type :: :queue.queue(any())

0 commit comments

Comments
 (0)