Skip to content

Commit

Permalink
Rename logical type configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
Strech committed Dec 7, 2023
1 parent 281019a commit bb23220
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/avrora/avro_type_converter/primitive_into_logical.ex
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ defmodule Avrora.AvroTypeConverter.PrimitiveIntoLogical do
do: {:error, %Avrora.Errors.ConfigurationError{code: :missing_decimal_lib}}
end

defp enabled, do: Config.self().decode_logical_types() == true
defp enabled, do: Config.self().cast_logical_types() == true
end
2 changes: 1 addition & 1 deletion lib/avrora/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ defmodule Avrora.Client do
def registry_schemas_autoreg, do: get(@opts, :registry_schemas_autoreg, true)
def convert_null_values, do: get(@opts, :convert_null_values, true)
def convert_map_to_proplist, do: get(@opts, :convert_map_to_proplist, false)
def decode_logical_types, do: get(@opts, :decode_logical_types, true)
def cast_logical_types, do: get(@opts, :cast_logical_types, true)
def names_cache_ttl, do: get(@opts, :names_cache_ttl, :infinity)
def decoder_hook, do: get(@opts, :decoder_hook, fn _, _, data, fun -> fun.(data) end)
def file_storage, do: unquote(:"Elixir.#{module}.Storage.File")
Expand Down
6 changes: 3 additions & 3 deletions lib/avrora/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Avrora.Config do
* `convert_map_to_proplist` bring back old behavior and configure decoding AVRO map-type as proplist, default `false`
TODO Rename into cast_logical_types
TODO Introduce configurable list of logical type casting
* `decode_logical_types` convert logical AVRO primitive or complex type into corresponding Elixir representation, default `true`
* `cast_logical_types` convert logical AVRO primitive or complex type into corresponding Elixir representation, default `true`
* `names_cache_ttl` duration to cache global schema names millisecods, default `:infinity`
* `decoder_hook` function to amend decoded payload, default `fn _, _, data, fun -> fun.(data) end`
Expand All @@ -34,7 +34,7 @@ defmodule Avrora.Config do
@callback registry_schemas_autoreg :: boolean()
@callback convert_null_values :: boolean()
@callback convert_map_to_proplist :: boolean()
@callback decode_logical_types :: boolean()
@callback cast_logical_types :: boolean()
@callback names_cache_ttl :: integer() | atom()
@callback decoder_hook :: (any(), any(), any(), any() -> any())
@callback file_storage :: module()
Expand Down Expand Up @@ -70,7 +70,7 @@ defmodule Avrora.Config do
def convert_map_to_proplist, do: get_env(:convert_map_to_proplist, false)

@doc false
def decode_logical_types, do: get_env(:decode_logical_types, true)
def cast_logical_types, do: get_env(:cast_logical_types, true)

@doc false
def names_cache_ttl, do: get_env(:names_cache_ttl, :infinity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Avrora.AvroTypeConverter.PrimitiveIntoLogicalTest do

describe "convert/2" do
test "when logical types must be kept as is" do
stub(Avrora.ConfigMock, :decode_logical_types, fn -> false end)
stub(Avrora.ConfigMock, :cast_logical_types, fn -> false end)

{:ok, decoded} = Codec.Plain.decode(date_message(), schema: schema(date_json()))

Expand Down
4 changes: 2 additions & 2 deletions test/avrora/codec/plain_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ defmodule Avrora.Codec.PlainTest do
end

test "when decoding message and logical types must be as is" do
stub(Avrora.ConfigMock, :decode_logical_types, fn -> false end)
stub(Avrora.ConfigMock, :cast_logical_types, fn -> false end)

{:ok, decoded} = Codec.Plain.decode(convertable_message(), schema: convertable_schema())

Expand All @@ -146,7 +146,7 @@ defmodule Avrora.Codec.PlainTest do

test "when decoding message and all types must be as is" do
stub(Avrora.ConfigMock, :convert_null_values, fn -> false end)
stub(Avrora.ConfigMock, :decode_logical_types, fn -> false end)
stub(Avrora.ConfigMock, :cast_logical_types, fn -> false end)

{:ok, decoded} = Codec.Plain.decode(convertable_message(), schema: convertable_schema())

Expand Down
2 changes: 1 addition & 1 deletion test/support/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule Support.Config do
@impl true
def convert_map_to_proplist, do: false
@impl true
def decode_logical_types, do: true
def cast_logical_types, do: true
@impl true
def file_storage, do: Avrora.Storage.FileMock
@impl true
Expand Down

0 comments on commit bb23220

Please sign in to comment.