Packages
ecto_watch
0.13.1
1.1.0
1.0.0
0.15.1
0.15.0
0.14.0
0.13.3
0.13.2
0.13.1
0.13.0
0.12.6
0.12.5
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
0.11.2
0.11.1
0.11.0
0.10.0
0.9.11
0.9.10
0.9.9
0.9.8
0.9.7
0.9.6
0.9.5
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.1
0.8.0
0.7.0
0.6.0
0.6.0-rc2
0.6.0-rc1
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
EctoWatch allows you to easily get Phoenix.PubSub notifications directly from postgresql.
Current section
Files
Jump to
Current section
Files
lib/ecto_watch/helpers.ex
defmodule EctoWatch.Helpers do
@moduledoc false
require Logger
def label(schema_mod_or_label) do
if ecto_schema_mod?(schema_mod_or_label) do
module_to_label(schema_mod_or_label)
else
schema_mod_or_label
end
end
def module_to_label(module) do
module
|> Module.split()
|> Enum.join("_")
|> String.downcase()
end
def ecto_schema_mod?(schema_mod) do
schema_mod.__schema__(:fields)
true
rescue
UndefinedFunctionError -> false
end
def validate_list(list, func) when is_list(list) do
result =
list
|> Enum.map(func)
first_error =
result
|> Enum.find(&match?({:error, _}, &1))
first_error || {:ok, Enum.map(result, fn {:ok, value} -> value end)}
end
def validate_list(_, _) do
{:error, "should be a list"}
end
def debug_log(watcher_identifier, message) do
Logger.debug("EctoWatch | #{inspect(watcher_identifier)} | #{inspect(self())} | #{message}")
end
end