Skip to content

Commit

Permalink
[FIX] Apply comments to uuid_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancisMurillo committed Sep 16, 2021
1 parent 55d7c18 commit 445ba8b
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 16 deletions.
12 changes: 3 additions & 9 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,12 @@ defmodule Commanded.Application do
@type uuid :: String.t()

@doc false
@spec uuid_generator(Commanded.Application.t(), boolean()) :: (() -> uuid) | nil
def uuid_generator(application, true) do
application
|> Config.get(:uuid_generator)
|> check_generator(application)
end

def uuid_generator(application, _required) do
@spec uuid_generator!(Commanded.Application.t()) :: (() -> uuid) | nil
def uuid_generator!(application) do
try do
Config.get(application, :uuid_generator)
rescue
_ -> nil
_ -> fn -> nil end
end
|> check_generator(application)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/commanded/assertions/event_assertions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ defmodule Commanded.Assertions.EventAssertions do
@doc false
def with_subscription(application, callback_fn, opts \\ [])
when is_function(callback_fn, 1) do
uuid_generator = Commanded.Application.uuid_generator(application, true)
subscription_name = uuid_generator.()
subscription_name = Commanded.Application.uuid_generator!(application).()
stream = Keyword.get(opts, :stream, :all)
start_from = Keyword.get(opts, :start_from, :origin)

Expand Down
2 changes: 1 addition & 1 deletion lib/commanded/commands/dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule Commanded.Commands.Dispatcher do

pipeline = before_dispatch(pipeline, payload)

uuid_generator = Application.uuid_generator(pipeline.application, true)
uuid_generator = Application.uuid_generator!(pipeline.application)

uuid_updater = fn
nil -> uuid_generator.()
Expand Down
2 changes: 1 addition & 1 deletion lib/commanded/commands/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ defmodule Commanded.Commands.Router do
opts = Keyword.merge(@command_opts, opts)

application = Keyword.fetch!(opts, :application)
uuid_generator = Application.uuid_generator(application, false) || fn -> nil end
uuid_generator = Application.uuid_generator!(application)
causation_id = Keyword.get(opts, :causation_id)
command_uuid = Keyword.get_lazy(opts, :command_uuid, uuid_generator)
consistency = Keyword.fetch!(opts, :consistency)
Expand Down
2 changes: 1 addition & 1 deletion lib/commanded/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Commanded.EventStore do
"""
def append_to_stream(application, stream_uuid, expected_version, events) do
{adapter, adapter_meta} = Application.event_store_adapter(application)
uuid_generator = Application.uuid_generator(application, true)
uuid_generator = Application.uuid_generator!(application)

events = Enum.map(events, &Map.put(&1, :event_id, uuid_generator.()))

Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ defmodule Commanded.Mixfile do
{:telemetry_registry, "~> 0.2"},

# Optional dependencies
{:elixir_uuid, "~> 1.2", optional: true},
{:jason, "~> 1.2", optional: true},
{:phoenix_pubsub, "~> 2.0", optional: true},

Expand Down
1 change: 0 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"benchfella": {:hex, :benchfella, "0.3.5", "b2122c234117b3f91ed7b43b6e915e19e1ab216971154acd0a80ce0e9b8c05f5", [:mix], [], "hexpm", "23f27cbc482cbac03fc8926441eb60a5e111759c17642bac005c3225f5eb809d"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"},
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.25.2", "4f1cae793c4d132e06674b282f1d9ea3bf409bcca027ddb2fe177c4eed6a253f", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5b0c172e87ac27f14dfd152d52a145238ec71a95efbf29849550278c58a393d6"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
Expand Down
1 change: 1 addition & 0 deletions test/aggregates/aggregate_state_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Commanded.Aggregates.AggregateStateTest do
use ExUnit.Case

alias Commanded.UUID
alias Commanded.DefaultApp

alias Commanded.Aggregates.{
Expand Down

0 comments on commit 445ba8b

Please sign in to comment.