Skip to content

Commit fbd3108

Browse files
committed
Support overridable messages for the GuardedStruct module
Support overridable messages for the `GuardedStruct` module with support for multiple languages Close #10
1 parent 8e93175 commit fbd3108

File tree

7 files changed

+532
-163
lines changed

7 files changed

+532
-163
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Changelog for GuardedStruct 0.0.4
2+
3+
- Fix deprecated code from Elixir 1.18
4+
- Support overridable messages for the `GuardedStruct` module with support for multiple languages
5+
16
# Changelog for GuardedStruct 0.0.3
27

38
- Fix deprecated code from Elixir 1.18.0-rc.0

lib/derive/parser.ex

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule GuardedStruct.Derive.Parser do
2+
import GuardedStruct.Messages, only: [translated_message: 1]
3+
24
@spec parser(list(String.t()) | String.t()) :: any()
35
def parser(inputs) when is_list(inputs) do
46
Enum.map(inputs, &parser(&1))
@@ -35,14 +37,7 @@ defmodule GuardedStruct.Derive.Parser do
3537
{:sub_field, line, add_parent_tags(items, parent)}
3638

3739
{:conditional_field, line, items} ->
38-
raise("""
39-
\n ----------------------------------------------------------\n
40-
Unfortunately, this macro does not support the nested mode in the conditional_field macro.
41-
If you can add this feature I would be very happy to send a PR.
42-
More information: https://github.com/mishka-group/guarded_struct/issues/7
43-
Parent Issue: https://github.com/mishka-group/guarded_struct/issues/8
44-
\n ----------------------------------------------------------\n
45-
""")
40+
raise(translated_message(:unsupported_conditional_field))
4641

4742
{:conditional_field, line,
4843
elements_unification(add_parent_tags(items, parent, "conds"), parent)}
@@ -58,14 +53,7 @@ defmodule GuardedStruct.Derive.Parser do
5853
{:sub_field, line, add_parent_tags(items, parent)}
5954

6055
{:conditional_field, line, items} ->
61-
raise("""
62-
\n ----------------------------------------------------------\n
63-
Unfortunately, this macro does not support the nested mode in the conditional_field macro.
64-
If you can add this feature I would be very happy to send a PR.
65-
More information: https://github.com/mishka-group/guarded_struct/issues/7
66-
Parent Issue: https://github.com/mishka-group/guarded_struct/issues/8
67-
\n ----------------------------------------------------------\n
68-
""")
56+
raise(translated_message(:unsupported_conditional_field))
6957

7058
comverted_items = add_parent_tags(items, parent, "conds")
7159

@@ -251,11 +239,7 @@ defmodule GuardedStruct.Derive.Parser do
251239

252240
def field_value(output) when is_list(output), do: output
253241

254-
def field_value(nil),
255-
do:
256-
raise(
257-
"Oh no!, I think you have not made all the subfields of a conditional field to the same name"
258-
)
242+
def field_value(nil), do: raise(translated_message(:parser_field_value))
259243

260244
@spec conds_list(list(map()) | map(), String.t()) :: any()
261245
def conds_list(data, parent_key) do

0 commit comments

Comments
 (0)