Skip to content

Commit

Permalink
Cosmetics in Flattenable
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Matiushkin committed Feb 6, 2024
1 parent 7d0275e commit 5656391
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/estructura/flattenable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ defimpl Estructura.Flattenable, for: Any do
quote do
defimpl Estructura.Flattenable, for: unquote(module) do
def flatten(input, options) do
options = Keyword.merge(unquote(options), options)
options =
unquote(options)
|> Keyword.merge(options)
|> Keyword.update(:only, [], fn only -> Enum.map(only, &to_string/1) end)
|> Keyword.update(:except, [], fn except -> Enum.map(except, &to_string/1) end)

input
|> Map.from_struct()
Expand Down
12 changes: 8 additions & 4 deletions lib/estructura/tree.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ defmodule Estructura.Tree do
]
]}
]},
content: {StreamData, :tree, [{StreamData, :fixed_list, [[]]}, &Estructura.Tree.child_gen/1]}
content:
{StreamData, :tree, [{StreamData, :fixed_list, [[]]}, &Estructura.Tree.child_gen/1]}
]

if {:module, Jason} == Code.ensure_compiled(Jason) do
@derive {Jason.Encoder, only: [:name, :attributes, :content]}
@derive {Jason.Encoder, only: ~w|name attributes content|a}
end

@derive {Estructura.Flattenable, only: ~w|name attributes content|a}

defstruct name: nil, attributes: %{}, content: []

@type t :: %{
Expand Down Expand Up @@ -190,7 +193,8 @@ defmodule Estructura.Tree do
{1, nil},
{2, StreamData.string(:alphanumeric)},
{7, Estructura.Tree.__generator__()}
]),
max_length: @max_children)
]),
max_length: @max_children
)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Estructura.MixProject do
use Mix.Project

@app :estructura
@version "1.2.3"
@version "1.2.4"

def project do
[
Expand Down

0 comments on commit 5656391

Please sign in to comment.