Skip to content

Commit

Permalink
VIP - Add MishkaInstaller.Event.Event module - event doc without queries
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed Jun 19, 2024
1 parent bafe5b7 commit 5387008
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 5 deletions.
272 changes: 272 additions & 0 deletions lib/event/event.ex

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion lib/event/hook.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule MishkaInstaller.Event.Hook do
@moduledoc """
"""
alias MishkaInstaller.Event.{Event, ModuleStateCompiler}

@spec __using__(keyword()) :: Macro.t()
Expand Down Expand Up @@ -193,6 +196,9 @@ defmodule MishkaInstaller.Event.Hook do
####################################################################################
######################### (▰˘◡˘▰) Functions (▰˘◡˘▰) ##########################
####################################################################################
@doc """
"""
@spec call(String.t(), any(), keyword()) :: any()
def call(event, data, args \\ []) do
module = ModuleStateCompiler.module_event_name(event)
Expand All @@ -204,6 +210,9 @@ defmodule MishkaInstaller.Event.Hook do
end
end

@doc """
"""
@spec call!(String.t(), any(), keyword()) :: any()
def call!(event, data, args \\ []) do
module = ModuleStateCompiler.module_event_name(event)
Expand All @@ -213,8 +222,8 @@ defmodule MishkaInstaller.Event.Hook do
####################################################################################
########################## (▰˘◡˘▰) Helper (▰˘◡˘▰) ############################
####################################################################################
@spec start_helper(module(), keyword(), any()) :: keyword()
@doc false
@spec start_helper(module(), keyword(), any()) :: keyword()
def start_helper(module, state, reg_db_plg) do
case module.start() do
{:ok, st_db_plg} ->
Expand Down
26 changes: 26 additions & 0 deletions lib/event/module_state_compiler.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
defmodule MishkaInstaller.Event.ModuleStateCompiler do
@moduledoc """
"""
@state_dir "MishkaInstaller.Event.ModuleStateCompiler.State."

@type error_return :: {:error, [%{action: atom(), field: atom(), message: String.t()}]}
####################################################################################
######################### (▰˘◡˘▰) Functions (▰˘◡˘▰) ##########################
####################################################################################
@doc """
"""
@spec create(list(struct()), String.t()) :: :ok | error_return
def create(plugins, event) do
module = module_event_name(event)
Expand Down Expand Up @@ -80,12 +86,18 @@ defmodule MishkaInstaller.Event.ModuleStateCompiler do
{:error, [%{message: "Unexpected error", field: :event, action: :compile}]}
end

@doc """
"""
@spec purge_create(list(struct()), String.t()) :: :ok | error_return
def purge_create(plugins, event) do
purge(event)
create(plugins, event)
end

@doc """
"""
@spec purge(list(String.t()) | String.t()) :: :ok
def purge(events) when is_list(events) do
Enum.each(events, &purge(&1))
Expand All @@ -102,6 +114,7 @@ defmodule MishkaInstaller.Event.ModuleStateCompiler do
####################################################################################
########################## (▰˘◡˘▰) Helper (▰˘◡˘▰) ############################
####################################################################################
@doc false
@spec module_event_name(String.t()) :: module()
def module_event_name(event) do
event
Expand All @@ -113,9 +126,15 @@ defmodule MishkaInstaller.Event.ModuleStateCompiler do
|> then(&Module.concat([&1]))
end

@doc """
"""
@spec initialize?(String.t()) :: boolean()
def initialize?(event), do: module_event_name(event).initialize?

@doc """
"""
@spec rescue_initialize?(String.t()) :: boolean()
def rescue_initialize?(event) do
module = module_event_name(event)
Expand All @@ -124,18 +143,25 @@ defmodule MishkaInstaller.Event.ModuleStateCompiler do
_ -> false
end

@doc """
"""
@spec compile_initialize?(String.t()) :: boolean()
def compile_initialize?(event) do
module = module_event_name(event)
Code.ensure_loaded?(module)
end

@doc """
"""
@spec safe_initialize?(String.t()) :: boolean()
def safe_initialize?(event) do
module = module_event_name(event)
function_exported?(module, :initialize?, 0)
end

@doc false
@spec perform(list(), {:reply, any()} | {:reply, :halt, any()}) :: any()
def perform([], {:reply, state}), do: state

Expand Down
9 changes: 9 additions & 0 deletions lib/installer/downloader.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule MishkaInstaller.Installer.Downloader do
@moduledoc """
"""
@hex_path "https://hex.pm/api/packages"
@hex_preview_path "https://repo.hex.pm/preview"
@github_path "https://raw.githubusercontent.com"
Expand Down Expand Up @@ -29,6 +32,9 @@ defmodule MishkaInstaller.Installer.Downloader do
####################################################################################
######################### (▰˘◡˘▰) Functions (▰˘◡˘▰) ##########################
####################################################################################
@doc """
"""
@spec download(download_type, pkg) :: okey_return | error_return
def download(:hex, %{app: app, tag: tag_name}) do
case build_url("https://repo.hex.pm/tarballs/#{app}-#{tag_name}.tar") do
Expand Down Expand Up @@ -114,6 +120,9 @@ defmodule MishkaInstaller.Installer.Downloader do
# ************************************************************
# ************************************************************
# ************************************************************
@doc """
"""
@spec get_mix(download_type, pkg) :: okey_return | error_return
def get_mix(:hex, %{app: app, tag: tag_name}) do
get_mix(:url, %{path: "#{@hex_preview_path}/#{app}/#{tag_name}/mix.exs"})
Expand Down
3 changes: 1 addition & 2 deletions lib/installer/port_handler.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmodule MishkaInstaller.Installer.PortHandler do
@moduledoc false
# Based on
# https://github.com/happening-oss/kafka-client/blob/develop/lib/kafka_client/gen_port.ex
# Based on https://github.com/happening-oss/kafka-client/blob/develop/lib/kafka_client/gen_port.ex

use GenServer
require Logger
Expand Down
1 change: 0 additions & 1 deletion lib/installer/run_time_sourcing.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
defmodule MishkaInstaller.Installer.RunTimeSourcing do

end
2 changes: 2 additions & 0 deletions lib/mishka_installer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ defmodule MishkaInstaller do
end
end

@doc false
def subscribe(channel) do
Phoenix.PubSub.subscribe(MishkaInstaller.PubSub, "mishka:plugin:#{channel}")
end

@doc false
def unsubscribe(channel) do
Phoenix.PubSub.unsubscribe(MishkaInstaller.PubSub, "mishka:plugin:#{channel}")
end
Expand Down
1 change: 1 addition & 0 deletions lib/mnesia_repo.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule MishkaInstaller.MnesiaRepo do
@moduledoc false
use GenServer
require Logger
alias MishkaInstaller.Event.Event
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule MishkaInstaller.MixProject do
{:mishka_developer_tools, github: "mishka-group/mishka_developer_tools"},
{:telemetry, "~> 1.2.1"},

# Dev dependencies
# Dev and Test dependencies
{:ex_doc, "~> 0.34.0", only: :dev, runtime: false}
]
end
Expand Down

0 comments on commit 5387008

Please sign in to comment.