Current section
Files
Jump to
Current section
Files
doc/TUID.ParameterizedType.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.30.2">
<meta name="project" content="tuid v0.1.0">
<title>TUID.ParameterizedType — tuid v0.1.0</title>
<link rel="stylesheet" href="dist/html-elixir-JUCHUGAD.css" />
<script src="dist/handlebars.runtime-NWIB6V2M.js"></script>
<script src="dist/handlebars.templates-NBND3S2D.js"></script>
<script src="dist/sidebar_items-26F77865.js"></script>
<script src="docs_config.js"></script>
<script async src="dist/html-WC6MMJK3.js"></script>
</head>
<body data-type="modules" class="page-module">
<script>
try {
var settings = JSON.parse(localStorage.getItem('ex_doc:settings') || '{}');
if (settings.theme === 'dark' ||
((settings.theme === 'system' || settings.theme == null) &&
window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
document.body.classList.add('dark')
}
} catch (error) { }
</script>
<div class="main">
<button class="sidebar-button sidebar-toggle" aria-label="toggle sidebar">
<i class="ri-menu-line ri-lg" title="Collapse/expand sidebar"></i>
</button>
<section class="sidebar">
<form class="sidebar-search" action="search.html">
<button type="submit" class="search-button" aria-label="Submit Search">
<i class="ri-search-2-line" aria-hidden="true" title="Submit search"></i>
</button>
<button type="button" tabindex="-1" class="search-close-button" aria-label="Cancel Search">
<i class="ri-close-line ri-lg" aria-hidden="true" title="Cancel search"></i>
</button>
<label class="search-label">
<p class="sr-only">Search</p>
<input name="q" type="text" class="search-input" placeholder="Search..." aria-label="Input your search terms" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
</label>
</form>
<div class="autocomplete">
<div class="autocomplete-results">
</div>
</div>
<div class="sidebar-header">
<div class="sidebar-projectDetails">
<a href="api-reference.html" class="sidebar-projectName" translate="no">
tuid
</a>
<div class="sidebar-projectVersion" translate="no">
v0.1.0
</div>
</div>
<ul class="sidebar-listNav">
<li><a id="extras-list-link" href="#full-list">Pages</a></li>
<li><a id="modules-list-link" href="#full-list">Modules</a></li>
</ul>
</div>
<div class="gradient"></div>
<ul id="full-list"></ul>
</section>
<section class="content">
<output role="status" id="toast"></output>
<div class="content-outer">
<div id="content" class="content-inner">
<h1>
<button class="icon-action display-settings">
<i class="ri-settings-3-line"></i>
<span class="sr-only">Settings</span>
</button>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L1" title="View Source" class="icon-action" rel="help">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
<span translate="no">TUID.ParameterizedType</span>
<small class="app-vsn" translate="no">(tuid v0.1.0)</small>
</h1>
<section id="moduledoc">
<p>Documentation for <a href="TUID.ParameterizedType.html#content"><code class="inline">TUID.ParameterizedType</code></a>.</p><p>ParameterizedType implemention for use with Ecto to use TUIDs (tagged, unique ids) as Ecto Types.</p>
</section>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<i class="ri-link-m" aria-hidden="true"></i>
Summary
</a>
</h1>
<div class="summary-functions summary">
<h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#autogenerate/1" translate="no">autogenerate(params)</a>
</div>
<div class="summary-synopsis"><p>Generates a loaded version of the data.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#cast/2" translate="no">cast(data, params)</a>
</div>
<div class="summary-synopsis"><p>Casts the given input to the ParameterizedType with the given parameters.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#dump/3" translate="no">dump(slug, dumper, params)</a>
</div>
<div class="summary-synopsis"><p>Dumps the given term into an Ecto native type.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#embed_as/2" translate="no">embed_as(format, params)</a>
</div>
<div class="summary-synopsis"><p>Dictates how the type should be treated inside embeds.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#equal?/3" translate="no">equal?(term1, term2, params)</a>
</div>
<div class="summary-synopsis"><p>Returns the underlying schema type for the ParameterizedType.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#init/1" translate="no">init(opts)</a>
</div>
<div class="summary-synopsis"><p>Callback to convert the options specified in the field macro into parameters
to be used in other callbacks.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#load/3" translate="no">load(data, loader, params)</a>
</div>
<div class="summary-synopsis"><p>Loads the given term into a ParameterizedType.</p></div>
</div>
</div>
</section>
<section id="functions" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#functions">
<i class="ri-link-m" aria-hidden="true"></i>
Functions
</a>
</h1>
<div class="functions-list">
<section class="detail" id="autogenerate/1">
<div class="detail-header">
<a href="#autogenerate/1" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">autogenerate(params)</h1>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L154" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Generates a loaded version of the data.</p><p>This callback is invoked when a parameterized type is given
to <code class="inline">field</code> with the <code class="inline">:autogenerate</code> flag.</p>
</section>
</section>
<section class="detail" id="cast/2">
<div class="detail-header">
<a href="#cast/2" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">cast(data, params)</h1>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L69" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Casts the given input to the ParameterizedType with the given parameters.</p><p>Specifically, convert a TUID, such as <code class="inline">user_C19xa4ANGXSz72USEyc2m</code> to a binary UUID for storage into the DB.</p><p>For more information on casting, see <a href="https://hexdocs.pm/ecto/3.10.3/Ecto.Type.html#c:cast/1"><code class="inline">Ecto.Type.cast/1</code></a>.</p>
</section>
</section>
<section class="detail" id="dump/3">
<div class="detail-header">
<a href="#dump/3" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">dump(slug, dumper, params)</h1>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L138" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Dumps the given term into an Ecto native type.</p><p>It receives a <code class="inline">dumper</code> function in case the parameterized
type is also a composite type. In order to dump the inner
type, the <code class="inline">dumper</code> must be called with the inner type and
the inner value as argument.</p><p>For more information on dumping, see <a href="https://hexdocs.pm/ecto/3.10.3/Ecto.Type.html#c:dump/1"><code class="inline">Ecto.Type.dump/1</code></a>.
Note that this callback <em>will</em> be called when dumping a <code class="inline">nil</code>
value, unlike <a href="https://hexdocs.pm/ecto/3.10.3/Ecto.Type.html#c:dump/1"><code class="inline">Ecto.Type.dump/1</code></a>.</p>
</section>
</section>
<section class="detail" id="embed_as/2">
<div class="detail-header">
<a href="#embed_as/2" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">embed_as(format, params)</h1>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L164" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Dictates how the type should be treated inside embeds.</p><p>For more information on embedding, see <a href="https://hexdocs.pm/ecto/3.10.3/Ecto.Type.html#c:embed_as/1"><code class="inline">Ecto.Type.embed_as/1</code></a></p>
</section>
</section>
<section class="detail" id="equal?/3">
<div class="detail-header">
<a href="#equal?/3" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">equal?(term1, term2, params)</h1>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L172" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Returns the underlying schema type for the ParameterizedType.</p><p>For more information on schema types, see <a href="https://hexdocs.pm/ecto/3.10.3/Ecto.Type.html#c:type/0"><code class="inline">Ecto.Type.type/0</code></a></p>
</section>
</section>
<section class="detail" id="init/1">
<div class="detail-header">
<a href="#init/1" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">init(opts)</h1>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L33" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Callback to convert the options specified in the field macro into parameters
to be used in other callbacks.</p><p>This function is called at compile time, and should raise if invalid values are
specified. It is idiomatic that the parameters returned from this are a map.
<code class="inline">field</code> and <code class="inline">schema</code> will be injected into the options automatically.</p><p>For example, this schema specification</p><pre><code class="makeup elixir" translate="no"><span class="n">schema</span><span class="w"> </span><span class="s">"my_table"</span><span class="w"> </span><span class="k" data-group-id="7762832834-1">do</span><span class="w">
</span><span class="n">field</span><span class="w"> </span><span class="ss">:my_field</span><span class="p">,</span><span class="w"> </span><span class="nc">MyParameterizedType</span><span class="p">,</span><span class="w"> </span><span class="ss">opt1</span><span class="p">:</span><span class="w"> </span><span class="ss">:foo</span><span class="p">,</span><span class="w"> </span><span class="ss">opt2</span><span class="p">:</span><span class="w"> </span><span class="no">nil</span><span class="w">
</span><span class="k" data-group-id="7762832834-1">end</span></code></pre><p>will result in the call:</p><pre><code class="makeup elixir" translate="no"><span class="nc">MyParameterizedType</span><span class="o">.</span><span class="n">init</span><span class="p" data-group-id="0684168843-1">(</span><span class="p" data-group-id="0684168843-2">[</span><span class="ss">schema</span><span class="p">:</span><span class="w"> </span><span class="s">"my_table"</span><span class="p">,</span><span class="w"> </span><span class="ss">field</span><span class="p">:</span><span class="w"> </span><span class="ss">:my_field</span><span class="p">,</span><span class="w"> </span><span class="ss">opt1</span><span class="p">:</span><span class="w"> </span><span class="ss">:foo</span><span class="p">,</span><span class="w"> </span><span class="ss">opt2</span><span class="p">:</span><span class="w"> </span><span class="no">nil</span><span class="p" data-group-id="0684168843-2">]</span><span class="p" data-group-id="0684168843-1">)</span></code></pre>
</section>
</section>
<section class="detail" id="load/3">
<div class="detail-header">
<a href="#load/3" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">load(data, loader, params)</h1>
<a href="https://github.com/amattn/tuid/blob/main/lib/tuid_type.ex#L113" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Loads the given term into a ParameterizedType.</p><p>It receives a <code class="inline">loader</code> function in case the parameterized
type is also a composite type. In order to load the inner
type, the <code class="inline">loader</code> must be called with the inner type and
the inner value as argument.</p><p>For more information on loading, see <a href="https://hexdocs.pm/ecto/3.10.3/Ecto.Type.html#c:load/1"><code class="inline">Ecto.Type.load/1</code></a>.
Note that this callback <em>will</em> be called when loading a <code class="inline">nil</code>
value, unlike <a href="https://hexdocs.pm/ecto/3.10.3/Ecto.Type.html#c:load/1"><code class="inline">Ecto.Type.load/1</code></a>.</p>
</section>
</section>
</div>
</section>
<footer class="footer">
<p>
<span class="line">
<a href="https://hex.pm/packages/tuid/0.1.0" class="footer-hex-package">Hex Package</a>
<a href="https://preview.hex.pm/preview/tuid/0.1.0">Hex Preview</a>
(<a href="https://preview.hex.pm/preview/tuid/0.1.0/show/lib/tuid_type.ex">current file</a>)
</span>
<span class="line">
<button class="a-main footer-button display-quick-switch" title="Search HexDocs packages">
Search HexDocs
</button>
<a href="tuid.epub" title="ePub version">
Download ePub version
</a>
</span>
</p>
<p class="built-using">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener" translate="no">ExDoc</a> (v0.30.2) for the
<a href="https://elixir-lang.org" title="Elixir" target="_blank" translate="no">Elixir programming language</a>
</p>
</footer>
</div>
</div>
</section>
</div>
</body>
</html>