Skip to content

Commit

Permalink
VIP - change Mix.env to installer function
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed Jun 27, 2024
1 parent 54ee62b commit 04aa8c9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule MishkaInstaller.Application do
Supervisor.start_link(children, opts)
end

if Mix.env() == :test do
if MishkaInstaller.__information__().env == :test do
def supervised_children() do
[]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/event/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule MishkaInstaller.Event.Event do
################################################################################
@doc false
@spec database_config() :: keyword()
if Mix.env() != :test do
if MishkaInstaller.__information__().env != :test do
def database_config(),
do: Keyword.merge(@mnesia_info, attributes: keys(), disc_copies: [node()])
else
Expand Down
2 changes: 1 addition & 1 deletion lib/installer/installer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defmodule MishkaInstaller.Installer.Installer do
################################################################################
@doc false
@spec database_config() :: keyword()
if Mix.env() != :test do
if MishkaInstaller.__information__().env != :test do
def database_config(),
do: Keyword.merge(@mnesia_info, attributes: keys(), disc_copies: [node()])
else
Expand Down
5 changes: 2 additions & 3 deletions lib/mnesia_repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule MishkaInstaller.MnesiaRepo do
alias MishkaInstaller.Installer.Installer
alias MnesiaAssistant.Error, as: MError

@env_mod Mix.env()
# I got the basic idea from https://github.com/processone/ejabberd
@identifier :mishka_mnesia_repo
####################################################################################
Expand Down Expand Up @@ -44,7 +43,7 @@ defmodule MishkaInstaller.MnesiaRepo do
"Identifier: #{inspect(@identifier)} ::: Placing Mnesia address of the generator in the mentioned system variable."
)

mnesia_dir = ".mnesia" <> "/#{@env_mod}"
mnesia_dir = ".mnesia" <> "/#{MishkaInstaller.__information__().env}"
config = Application.get_env(:mishka, Mishka.MnesiaRepo, mnesia_dir: mnesia_dir)
File.mkdir_p(config[:mnesia_dir]) |> MError.error_description(@identifier)
Application.put_env(:mnesia, :dir, config[:mnesia_dir] |> to_charlist)
Expand Down Expand Up @@ -114,7 +113,7 @@ defmodule MishkaInstaller.MnesiaRepo do
end

@impl true
if Mix.env() != :test do
if MishkaInstaller.__information__().env != :test do
def handle_info(:health_check, state) do
# TODO: this function can have some checker
Process.send_after(__MODULE__, :health_check, 1000)
Expand Down

0 comments on commit 04aa8c9

Please sign in to comment.