Current section
37 Versions
Jump to
Current section
37 Versions
Compare versions
3
files changed
+23
additions
-8
deletions
| @@ -16,4 +16,4 @@ | |
| 16 16 | {<<"links">>,[{<<"GitHub">>,<<"https://github.com/CatTheMagician/talos">>}]}. |
| 17 17 | {<<"name">>,<<"talos">>}. |
| 18 18 | {<<"requirements">>,[]}. |
| 19 | - {<<"version">>,<<"1.7.1">>}. |
| 19 | + {<<"version">>,<<"1.7.2">>}. |
| @@ -4,6 +4,7 @@ defmodule Talos.Helpers.SchemaToMap do | |
| 4 4 | """ |
| 5 5 | |
| 6 6 | alias Talos.Types.MapType.Field |
| 7 | + alias Talos.Field, as: OldField |
| 7 8 | alias Talos.Types.MapType |
| 8 9 | alias Talos.Types.EnumType |
| 9 10 | alias Talos.Types.ListType |
| @@ -37,11 +38,23 @@ defmodule Talos.Helpers.SchemaToMap do | |
| 37 38 | } |
| 38 39 | end |
| 39 40 | |
| 41 | + def convert(%OldField{} = field) do |
| 42 | + %{ |
| 43 | + key: field.key, |
| 44 | + description: field.description, |
| 45 | + optional: field.optional, |
| 46 | + default_value: field.default_value, |
| 47 | + type_name: inspect(field.type.__struct__), |
| 48 | + type: convert(field.type) |
| 49 | + } |
| 50 | + end |
| 51 | + |
| 52 | + def convert(%{__struct__: _struct} = other) when is_map(other) do |
| 53 | + struct_to_map(other) |
| 54 | + end |
| 55 | + |
| 40 56 | def convert(other) when is_map(other) do |
| 41 | - case is_nil(other.__struct__) do |
| 42 | - true -> other |
| 43 | - false -> struct_to_map(other) |
| 44 | - end |
| 57 | + other |
| 45 58 | end |
| 46 59 | |
| 47 60 | def convert(other) do |
| @@ -52,15 +65,17 @@ defmodule Talos.Helpers.SchemaToMap do | |
| 52 65 | keys = Map.keys(struct) |
| 53 66 | |
| 54 67 | tuples = |
| 55 | - Enum.map(keys, fn key -> |
| 68 | + keys |
| 69 | + |> Enum.map(fn key -> |
| 56 70 | value = Map.get(struct, key) |
| 57 71 | |
| 58 72 | cond do |
| 59 | - :__struct__ == key -> {:type_name, inspect(value)} |
| 73 | + :__struct__ == key -> nil |
| 60 74 | :regexp == key && !is_nil(value) -> {key, inspect(value)} |
| 61 75 | true -> {key, value} |
| 62 76 | end |
| 63 77 | end) |
| 78 | + |> Enum.reject(&is_nil/1) |
| 64 79 | |
| 65 80 | map = Map.new(tuples) |
| @@ -4,7 +4,7 @@ defmodule Talos.MixProject do | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 6 | app: :talos, |
| 7 | - version: "1.7.1", |
| 7 | + version: "1.7.2", |
| 8 8 | elixir: ">= 1.8.0", |
| 9 9 | build_embedded: Mix.env() == :prod, |
| 10 10 | start_permanent: Mix.env() == :prod, |