From 5cfc96254c6313fdfdad5a2bdd3d6c60ac694447 Mon Sep 17 00:00:00 2001 From: Theodor Fiedler Date: Thu, 7 Nov 2024 12:08:23 +0100 Subject: [PATCH 1/2] add parentheses to module metadata function calls --- lib/remodel/formatters/list_formatter.ex | 4 ++-- lib/remodel/formatters/map_formatter.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/remodel/formatters/list_formatter.ex b/lib/remodel/formatters/list_formatter.ex index 0e97e11..6ca17d4 100644 --- a/lib/remodel/formatters/list_formatter.ex +++ b/lib/remodel/formatters/list_formatter.ex @@ -13,7 +13,7 @@ defmodule Remodel.Formatter.ListFormatter do do: Enum.map(resources, fn(resource) -> format_resources(resource, serializer, options) end) defp format_resources(resource, serializer, options) do - Enum.map serializer.__attributes, fn(attr) -> + Enum.map serializer.__attributes(), fn(attr) -> if !attr.if || apply(serializer, attr.if, [resource, options[:scope]]) do apply(serializer, attr.attribute, [resource, options[:scope]]) else @@ -23,5 +23,5 @@ defmodule Remodel.Formatter.ListFormatter do end defp format_header(serializer), - do: Enum.map(serializer.__attributes, fn(attr) -> to_string(attr.as || attr.attribute) end) + do: Enum.map(serializer.__attributes(), fn(attr) -> to_string(attr.as || attr.attribute) end) end diff --git a/lib/remodel/formatters/map_formatter.ex b/lib/remodel/formatters/map_formatter.ex index 8bc00cd..74ab0a7 100644 --- a/lib/remodel/formatters/map_formatter.ex +++ b/lib/remodel/formatters/map_formatter.ex @@ -11,7 +11,7 @@ defmodule Remodel.Formatter.MapFormatter do end defp format_resource(resource, serializer, options) when is_map(resource) do - Enum.reduce(serializer.__attributes, %{}, fn(attr, results) -> + Enum.reduce(serializer.__attributes(), %{}, fn(attr, results) -> if !attr.if || evaluate_conditional(resource, serializer, options, attr) do Map.put(results, attr.as || attr.attribute, apply(serializer, attr.attribute, [resource, options[:scope]])) else From 539255de9161ebf41a2a8e5dd0d0d1430fc1d5ba Mon Sep 17 00:00:00 2001 From: Theodor Fiedler Date: Thu, 7 Nov 2024 12:11:37 +0100 Subject: [PATCH 2/2] format Enum.map/2 --- lib/remodel/formatters/list_formatter.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/remodel/formatters/list_formatter.ex b/lib/remodel/formatters/list_formatter.ex index 6ca17d4..e2efbeb 100644 --- a/lib/remodel/formatters/list_formatter.ex +++ b/lib/remodel/formatters/list_formatter.ex @@ -13,13 +13,13 @@ defmodule Remodel.Formatter.ListFormatter do do: Enum.map(resources, fn(resource) -> format_resources(resource, serializer, options) end) defp format_resources(resource, serializer, options) do - Enum.map serializer.__attributes(), fn(attr) -> + Enum.map(serializer.__attributes(), fn(attr) -> if !attr.if || apply(serializer, attr.if, [resource, options[:scope]]) do apply(serializer, attr.attribute, [resource, options[:scope]]) else nil end - end + end) end defp format_header(serializer),