Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Use map() instead of Map.t()
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault Denizet committed Dec 3, 2018
1 parent 69b7424 commit b440d40
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions apps/activity_logger/lib/activity_logger/activity_log.ex
Expand Up @@ -69,7 +69,7 @@ defmodule ActivityLogger.ActivityLog do
Map.fetch!(config, schema)
end

@spec all_for_target(Map.t()) :: [%ActivityLog{}]
@spec all_for_target(map()) :: [%ActivityLog{}]
def all_for_target(record) do
all_for_target(record.__struct__, record.uuid)
end
Expand Down Expand Up @@ -98,7 +98,7 @@ defmodule ActivityLogger.ActivityLog do
)
end

@spec get_initial_originator(Map.t()) :: Map.t()
@spec get_initial_originator(map()) :: map()
def get_initial_originator(record) do
activity_log_type = get_type(record.__struct__)
activity_log = ActivityLog.get_initial_activity_log(activity_log_type, record.uuid)
Expand Down
2 changes: 1 addition & 1 deletion apps/activity_logger/lib/activity_logger/activity_repo.ex
Expand Up @@ -37,7 +37,7 @@ defmodule ActivityLogger.ActivityRepo do
|> handle_perform_result(:update, changeset)
end

@spec delete_record_with_activity_log(Map.t(), Keyword.t(), Multi.t()) ::
@spec delete_record_with_activity_log(map(), Keyword.t(), Multi.t()) ::
{:ok, any()}
| {:error, any()}
| {:error, :no_originator_given}
Expand Down
Expand Up @@ -18,7 +18,7 @@ defmodule EWallet.TransactionConsumptionConfirmerGate do
alias EWalletDB.{Repo, TransactionConsumption, TransactionRequest}
alias ActivityLogger.System

@spec approve_and_confirm(%TransactionRequest{}, %TransactionConsumption{}, Map.t()) ::
@spec approve_and_confirm(%TransactionRequest{}, %TransactionConsumption{}, map()) ::
{:error, %TransactionConsumption{}, atom(), String.t()}
| {:error, %TransactionConsumption{}, String.t(), String.t()}
def approve_and_confirm(request, consumption, originator) do
Expand Down
2 changes: 1 addition & 1 deletion apps/ewallet/lib/ewallet/gates/transaction_request_gate.ex
Expand Up @@ -175,7 +175,7 @@ defmodule EWallet.TransactionRequestGate do

def create(_, _attrs), do: {:error, :invalid_parameter}

@spec expire_if_past_expiration_date(%TransactionRequest{}, Map.t()) ::
@spec expire_if_past_expiration_date(%TransactionRequest{}, map()) ::
{:ok, %TransactionRequest{}}
| {:error, atom()}
| {:error, map()}
Expand Down
10 changes: 5 additions & 5 deletions apps/ewallet/lib/ewallet/web/originator.ex
Expand Up @@ -5,27 +5,27 @@ defmodule EWallet.Web.Originator do
alias EWalletDB.{Key, User}
alias ActivityLogger.ActivityLog

@spec extract(Map.t()) :: %Key{}
@spec extract(map()) :: %Key{}
def extract(%{key: key}) do
key
end

@spec extract(Map.t()) :: %User{}
@spec extract(map()) :: %User{}
def extract(%{admin_user: admin_user}) do
admin_user
end

@spec extract(Map.t()) :: %User{}
@spec extract(map()) :: %User{}
def extract(%{user: user}) do
user
end

@spec set_in_attrs(Map.t(), Map.t()) :: Map.t()
@spec set_in_attrs(map(), map()) :: map()
def set_in_attrs(attrs, originator, key \\ "originator") do
Map.put(attrs, key, extract(originator))
end

@spec get_initial_originator(Map.t()) :: Map.t()
@spec get_initial_originator(map()) :: map()
def get_initial_originator(record) do
ActivityLog.get_initial_originator(record)
end
Expand Down
8 changes: 4 additions & 4 deletions apps/ewallet_config/lib/ewallet_config/config.ex
Expand Up @@ -15,7 +15,7 @@ defmodule EWalletConfig.Config do
SettingLoader
}

@spec start_link(Map.t()) :: {:ok, pid()} | {:error, Atom.t()}
@spec start_link(map()) :: {:ok, pid()} | {:error, Atom.t()}
def start_link(named: true) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
Expand All @@ -30,7 +30,7 @@ defmodule EWalletConfig.Config do
GenServer.stop(pid)
end

@spec start_link(Map.t()) :: {:ok, []}
@spec start_link(map()) :: {:ok, []}
def init(_args) do
{:ok, []}
end
Expand Down Expand Up @@ -100,7 +100,7 @@ defmodule EWalletConfig.Config do
end)
end

@spec update(Map.t(), Atom.t()) :: [{:ok, %Setting{}} | {:error, Atom.t()}]
@spec update(map(), Atom.t()) :: [{:ok, %Setting{}} | {:error, Atom.t()}]
def update(attrs, pid \\ __MODULE__) do
{config_pid, attrs} = get_config_pid(attrs)

Expand Down Expand Up @@ -131,7 +131,7 @@ defmodule EWalletConfig.Config do

defp get_config_pid(attrs), do: {nil, attrs}

@spec insert_all_defaults(Map.t(), Atom.t()) :: :ok
@spec insert_all_defaults(map(), Atom.t()) :: :ok
def insert_all_defaults(opts \\ %{}, pid \\ __MODULE__) do
:ok = Setting.insert_all_defaults(opts)
reload_config(pid)
Expand Down
12 changes: 6 additions & 6 deletions apps/ewallet_config/lib/ewallet_config/setting.ex
Expand Up @@ -43,10 +43,10 @@ defmodule EWalletConfig.Setting do
:updated_at
]

@spec get_setting_mappings() :: [Map.t()]
@spec get_setting_mappings() :: [map()]
def get_setting_mappings, do: Application.get_env(:ewallet_config, :settings_mappings)

@spec get_default_settings() :: [Map.t()]
@spec get_default_settings() :: [map()]
def get_default_settings, do: Application.get_env(:ewallet_config, :default_settings)

@spec types() :: [String.t()]
Expand Down Expand Up @@ -108,7 +108,7 @@ defmodule EWalletConfig.Setting do
@doc """
Creates a new setting with the passed attributes.
"""
@spec insert(Map.t()) :: {:ok, %Setting{}} | {:error, %Changeset{}}
@spec insert(map()) :: {:ok, %Setting{}} | {:error, %Changeset{}}
def insert(attrs) do
attrs = cast_attrs(attrs)

Expand All @@ -121,7 +121,7 @@ defmodule EWalletConfig.Setting do
@doc """
Inserts all the default settings.
"""
@spec insert_all_defaults(Map.t()) :: [{:ok, %Setting{}}] | [{:error, %Changeset{}}]
@spec insert_all_defaults(map()) :: [{:ok, %Setting{}}] | [{:error, %Changeset{}}]
def insert_all_defaults(overrides \\ %{}) do
Repo.transaction(fn ->
get_default_settings()
Expand Down Expand Up @@ -156,7 +156,7 @@ defmodule EWalletConfig.Setting do
defp return_tx_result({:ok, false}), do: :error
defp return_tx_result({:error, _}), do: {:error, :setting_insert_failed}

@spec update(String.t(), Map.t()) ::
@spec update(String.t(), map()) ::
{:ok, %Setting{}} | {:error, Atom.t()} | {:error, Changeset.t()}
def update(nil, _), do: {:error, :setting_not_found}

Expand Down Expand Up @@ -195,7 +195,7 @@ defmodule EWalletConfig.Setting do
end)
end

@spec update_all(Map.t()) :: [{:ok, %Setting{}} | {:error, Atom.t()} | {:error, Changeset.t()}]
@spec update_all(map()) :: [{:ok, %Setting{}} | {:error, Atom.t()} | {:error, Changeset.t()}]
def update_all(attrs) do
Enum.map(attrs, fn {key, value} ->
{key, update(key, %{value: value})}
Expand Down
4 changes: 2 additions & 2 deletions apps/ewallet_db/lib/ewallet_db/account.ex
Expand Up @@ -539,7 +539,7 @@ defmodule EWalletDB.Account do
end)
end

@spec add_category(%Account{}, %Category{}, Map.t()) ::
@spec add_category(%Account{}, %Category{}, map()) ::
{:ok, %Account{}} | {:error, Ecto.Changeset.t()}
def add_category(account, category, originator) do
account = Repo.preload(account, :categories)
Expand All @@ -556,7 +556,7 @@ defmodule EWalletDB.Account do
})
end

@spec remove_category(%Account{}, %Category{}, Map.t()) ::
@spec remove_category(%Account{}, %Category{}, map()) ::
{:ok, %Account{}} | {:error, Ecto.Changeset.t()}
def remove_category(account, category, originator) do
account = Repo.preload(account, :categories)
Expand Down
2 changes: 1 addition & 1 deletion apps/ewallet_db/lib/ewallet_db/auth_token.ex
Expand Up @@ -70,7 +70,7 @@ defmodule EWalletDB.AuthToken do
)
end

@spec switch_account(%__MODULE__{}, %Account{}, Map.t()) ::
@spec switch_account(%__MODULE__{}, %Account{}, map()) ::
{:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
def switch_account(token, account, originator) do
token
Expand Down
4 changes: 2 additions & 2 deletions apps/ewallet_db/lib/ewallet_db/category.ex
Expand Up @@ -124,7 +124,7 @@ defmodule EWalletDB.Category do
Soft-deletes the given category. The operation fails if the category
has one more more accounts associated.
"""
@spec delete(%__MODULE__{}, Map.t()) ::
@spec delete(%__MODULE__{}, map()) ::
{:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()} | {:error, atom()}
def delete(category, originator) do
empty? =
Expand All @@ -142,6 +142,6 @@ defmodule EWalletDB.Category do
@doc """
Restores the given category from soft-delete.
"""
@spec restore(%__MODULE__{}, Map.t()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
@spec restore(%__MODULE__{}, map()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
def restore(category, originator), do: SoftDelete.restore(category, originator)
end
6 changes: 3 additions & 3 deletions apps/ewallet_db/lib/ewallet_db/exchange_pair.ex
Expand Up @@ -152,13 +152,13 @@ defmodule EWalletDB.ExchangePair do
@doc """
Soft-deletes the given exchange pair.
"""
@spec delete(%__MODULE__{}, Map.t()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
@spec delete(%__MODULE__{}, map()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
def delete(exchange_pair, originator), do: SoftDelete.delete(exchange_pair, originator)

@doc """
Restores the given exchange pair from soft-delete.
"""
@spec restore(%__MODULE__{}, Map.t()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
@spec restore(%__MODULE__{}, map()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
def restore(exchange_pair, originator) do
changeset = restore_changeset(exchange_pair, %{deleted_at: nil, originator: originator})

Expand All @@ -174,7 +174,7 @@ defmodule EWalletDB.ExchangePair do
@doc """
Touches the given exchange pair and updates `updated_at` to the current date & time.
"""
@spec touch(%__MODULE__{}, Map.t()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
@spec touch(%__MODULE__{}, map()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
def touch(exchange_pair, originator) do
exchange_pair
|> touch_changeset(%{updated_at: NaiveDateTime.utc_now(), originator: originator})
Expand Down
4 changes: 2 additions & 2 deletions apps/ewallet_db/lib/ewallet_db/key.ex
Expand Up @@ -190,13 +190,13 @@ defmodule EWalletDB.Key do
@doc """
Soft-deletes the given key.
"""
@spec delete(%Key{}, Map.t()) :: {:ok, %Key{}} | {:error, Ecto.Changeset.t()}
@spec delete(%Key{}, map()) :: {:ok, %Key{}} | {:error, Ecto.Changeset.t()}
def delete(key, originator), do: SoftDelete.delete(key, originator)

@doc """
Restores the given key from soft-delete.
"""
@spec restore(%Key{}, Map.t()) :: {:ok, %Key{}} | {:error, Ecto.Changeset.t()}
@spec restore(%Key{}, map()) :: {:ok, %Key{}} | {:error, Ecto.Changeset.t()}
def restore(key, originator), do: SoftDelete.restore(key, originator)

@doc """
Expand Down
4 changes: 2 additions & 2 deletions apps/ewallet_db/lib/ewallet_db/role.ex
Expand Up @@ -119,7 +119,7 @@ defmodule EWalletDB.Role do
Soft-deletes the given role. The operation fails if the role
has one more more users associated.
"""
@spec delete(%__MODULE__{}, Map.t()) ::
@spec delete(%__MODULE__{}, map()) ::
{:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()} | {:error, atom()}
def delete(role, originator) do
empty? =
Expand All @@ -137,7 +137,7 @@ defmodule EWalletDB.Role do
@doc """
Restores the given role from soft-delete.
"""
@spec restore(%__MODULE__{}, Map.t()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
@spec restore(%__MODULE__{}, map()) :: {:ok, %__MODULE__{}} | {:error, Ecto.Changeset.t()}
def restore(role, originator), do: SoftDelete.restore(role, originator)

@doc """
Expand Down
4 changes: 2 additions & 2 deletions apps/ewallet_db/lib/ewallet_db/soft_delete.ex
Expand Up @@ -113,7 +113,7 @@ defmodule EWalletDB.SoftDelete do
@doc """
Soft-deletes the given struct.
"""
@spec delete(struct(), Map.t()) :: any()
@spec delete(struct(), map()) :: any()
def delete(struct, originator) do
struct
|> soft_delete_changeset(%{
Expand All @@ -126,7 +126,7 @@ defmodule EWalletDB.SoftDelete do
@doc """
Restores the given struct from soft-delete.
"""
@spec restore(struct(), Map.t()) :: any()
@spec restore(struct(), map()) :: any()
def restore(struct, originator) do
struct
|> soft_delete_changeset(%{
Expand Down
8 changes: 4 additions & 4 deletions apps/ewallet_db/lib/ewallet_db/transaction_consumption.ex
Expand Up @@ -297,7 +297,7 @@ defmodule EWalletDB.TransactionConsumption do
@doc """
Expires the given consumption.
"""
@spec expire(%TransactionConsumption{}, Map.t()) ::
@spec expire(%TransactionConsumption{}, map()) ::
{:ok, %TransactionConsumption{}} | {:error, map()}
def expire(consumption, originator) do
consumption
Expand All @@ -312,7 +312,7 @@ defmodule EWalletDB.TransactionConsumption do
@doc """
Expires the given consumption if the expiration date is past.
"""
@spec expire_if_past_expiration_date(%TransactionConsumption{}, Map.t()) ::
@spec expire_if_past_expiration_date(%TransactionConsumption{}, map()) ::
{:ok, %TransactionConsumption{}} | {:error, map()}
def expire_if_past_expiration_date(consumption, originator) do
expired? =
Expand Down Expand Up @@ -388,13 +388,13 @@ defmodule EWalletDB.TransactionConsumption do
@doc """
Approves a consumption.
"""
@spec approve(%TransactionConsumption{}, Map.t()) :: %TransactionConsumption{}
@spec approve(%TransactionConsumption{}, map()) :: %TransactionConsumption{}
def approve(consumption, originator), do: state_transition(consumption, @approved, originator)

@doc """
Rejects a consumption.
"""
@spec reject(%TransactionConsumption{}, Map.t()) :: %TransactionConsumption{}
@spec reject(%TransactionConsumption{}, map()) :: %TransactionConsumption{}
def reject(consumption, originator) do
state_transition(consumption, @rejected, originator)
end
Expand Down
12 changes: 6 additions & 6 deletions apps/ewallet_db/lib/ewallet_db/transaction_request.ex
Expand Up @@ -270,7 +270,7 @@ defmodule EWalletDB.TransactionRequest do
@doc """
Touches a request by updating the `updated_at` field.
"""
@spec touch(%TransactionRequest{}, Map.t()) :: {:ok, %TransactionRequest{}} | {:error, map()}
@spec touch(%TransactionRequest{}, map()) :: {:ok, %TransactionRequest{}} | {:error, map()}
def touch(request, originator) do
request
|> touch_changeset(%{
Expand Down Expand Up @@ -328,7 +328,7 @@ defmodule EWalletDB.TransactionRequest do
@doc """
Expires the given request with the specified reason.
"""
@spec expire(%TransactionRequest{}, Map.t(), String.t()) ::
@spec expire(%TransactionRequest{}, map(), String.t()) ::
{:ok, %TransactionRequest{}} | {:error, map()}
def expire(request, originator, reason \\ "expired_transaction_request") do
request
Expand All @@ -344,7 +344,7 @@ defmodule EWalletDB.TransactionRequest do
@doc """
Expires the given request if the expiration date is past.
"""
@spec expire_if_past_expiration_date(%TransactionRequest{}, Map.t()) ::
@spec expire_if_past_expiration_date(%TransactionRequest{}, map()) ::
{:ok, %TransactionRequest{}} | {:error, map()}
def expire_if_past_expiration_date(request, originator) do
expired? =
Expand All @@ -360,7 +360,7 @@ defmodule EWalletDB.TransactionRequest do
@doc """
Expires the given request if the maximum number of consumptions has been reached.
"""
@spec expire_if_max_consumption(%TransactionRequest{}, Map.t()) ::
@spec expire_if_max_consumption(%TransactionRequest{}, map()) ::
{:ok, %TransactionRequest{}}
| {:error, map()}
def expire_if_max_consumption(request, originator) do
Expand All @@ -374,7 +374,7 @@ defmodule EWalletDB.TransactionRequest do
end
end

@spec load_consumptions_count(%TransactionRequest{}, Map.t()) :: Integer.t()
@spec load_consumptions_count(%TransactionRequest{}, map()) :: Integer.t()
def load_consumptions_count(request, originator) do
case request.consumptions_count do
nil ->
Expand All @@ -389,7 +389,7 @@ defmodule EWalletDB.TransactionRequest do
@spec update_consumptions_count(
%TransactionRequest{},
list(%TransactionConsumption{}),
Map.t()
map()
) :: %TransactionRequest{}
defp update_consumptions_count(request, consumptions, originator) do
{:ok, request} =
Expand Down
2 changes: 1 addition & 1 deletion apps/ewallet_db/lib/ewallet_db/user.ex
Expand Up @@ -579,7 +579,7 @@ defmodule EWalletDB.User do
@doc """
Sets the user's admin status.
"""
@spec set_admin(%User{}, boolean(), Map.t()) :: {:ok, %User{}} | {:error, Ecto.Changeset.t()}
@spec set_admin(%User{}, boolean(), map()) :: {:ok, %User{}} | {:error, Ecto.Changeset.t()}
def set_admin(user, boolean, originator) do
user
|> set_admin_changeset(%{
Expand Down

0 comments on commit b440d40

Please sign in to comment.