-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Investigating #165
- Loading branch information
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
examples/simple_app/lib/simple_app/typed_struct_example.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Shared.Data.Authorization do | ||
@moduledoc """ | ||
Saves authorization details for a user. It also contains other details. | ||
""" | ||
|
||
use TypedStruct | ||
|
||
alias Shared.Utils.Structs | ||
|
||
@type authorization :: %{ | ||
(cookie :: String.t()) => String.t(), | ||
(token :: String.t()) => String.t() | ||
} | ||
|
||
@derive Jason.Encoder | ||
typedstruct enforce: true do | ||
@typedoc "Authorization information for a user" | ||
|
||
field(:cookie, String.t()) | ||
field(:token, String.t()) | ||
end | ||
|
||
@spec new(authorization()) :: __MODULE__.t() | ||
def new(%{"cookie" => cookie, "token" => token} = auth) | ||
when is_binary(cookie) and is_binary(token) do | ||
Structs.string_map_to_struct(auth, __MODULE__) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
%{ | ||
"gradualizer": {:git, "https://github.com/josefs/Gradualizer.git", "6e89b4e1cd489637a848cc5ca55058c8a241bf7d", [ref: "6e89b4e"]}, | ||
"gradient_macros": {:git, "https://github.com/esl/gradient_macros.git", "bf5a066a6abd90cc63281d7ccb8eb7ac0fed0e64", [ref: "bf5a066"]}, | ||
"gradualizer": {:git, "https://github.com/josefs/Gradualizer.git", "1498d1792155010950c86dc3e92ccb111b706e80", [ref: "1498d17"]}, | ||
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"}, | ||
"typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"}, | ||
} |