make credo happy

This commit is contained in:
Victor Martinez 2024-03-29 16:24:26 +01:00
parent d1a093d8cc
commit fd7849dfb7
7 changed files with 26 additions and 8 deletions

View file

@ -1,5 +1,5 @@
defmodule Intisync.Puid do defmodule Intisync.Puid do
@doc """ @moduledoc """
Generate Probably unique identifiers Generate Probably unique identifiers
""" """
use Puid use Puid

View file

@ -1,4 +1,8 @@
defmodule Intisync.SessionPubSub do defmodule Intisync.SessionPubSub do
@moduledoc """
Provides function to publish/subscribe to IntiSync.PubSub topics
"""
def broadcast!(session_id, topic, event, payload) do def broadcast!(session_id, topic, event, payload) do
topic = "#{topic}:#{event}:#{session_id}" topic = "#{topic}:#{event}:#{session_id}"
payload = %{payload: payload, topic: topic} payload = %{payload: payload, topic: topic}

View file

@ -1,7 +1,12 @@
defmodule Intisync.SessionServer do defmodule Intisync.SessionServer do
alias Intisync.SessionPubSub @moduledoc """
Contains the business logic of a session.
It is the source of truth of the session state.
"""
use GenServer use GenServer
alias Intisync.SessionPubSub
def init(session_id) do def init(session_id) do
{:ok, {:ok,
%{ %{
@ -47,8 +52,8 @@ defmodule Intisync.SessionServer do
GenServer.call(pid, {:get_devices}) GenServer.call(pid, {:get_devices})
end end
def is_full?(pid) do def full?(pid) do
GenServer.call(pid, {:is_full?}) GenServer.call(pid, {:full?})
end end
def handle_call({:get_id}, _from, state) do def handle_call({:get_id}, _from, state) do
@ -59,10 +64,10 @@ defmodule Intisync.SessionServer do
{:reply, state.devices, state} {:reply, state.devices, state}
end end
def handle_call({:is_full?}, _from, state) do def handle_call({:full?}, _from, state) do
is_full? = state.remote_connection_status == :connected full? = state.remote_connection_status == :connected
{:reply, is_full?, state} {:reply, full?, state}
end end
def handle_call({:device_connected, index, device}, _from, state) do def handle_call({:device_connected, index, device}, _from, state) do

View file

@ -1,4 +1,7 @@
defmodule Intisync.SessionsSupervisor do defmodule Intisync.SessionsSupervisor do
@moduledoc """
DynamicSupervisor responsible to manage SessionServers
"""
use DynamicSupervisor use DynamicSupervisor
alias Intisync.SessionServer alias Intisync.SessionServer

View file

@ -1,4 +1,7 @@
defmodule IntisyncWeb.LiveViewMonitor do defmodule IntisyncWeb.LiveViewMonitor do
@moduledoc """
Monitors LiveView processes and calls their `unmount` functions when they die
"""
use GenServer use GenServer
def start_link(init_arg) do def start_link(init_arg) do

View file

@ -1,4 +1,7 @@
defmodule IntisyncWeb.DeviceCardComponent do defmodule IntisyncWeb.DeviceCardComponent do
@moduledoc """
Renders a device card
"""
use Phoenix.Component use Phoenix.Component
import IntisyncWeb.CoreComponents import IntisyncWeb.CoreComponents

View file

@ -52,7 +52,7 @@ defmodule IntisyncWeb.RemoteLive do
{:error, :not_found} {:error, :not_found}
pid -> pid ->
if SessionServer.is_full?(pid) do if SessionServer.full?(pid) do
{:error, :unauthorized} {:error, :unauthorized}
else else
{:ok, pid} {:ok, pid}