View Source Flint.Type (Flint v0.6.0)
Flint.Type is meant to make writing new Ecto types require much less boilerplate, because you can base your
type off of an existing type and only modify the callbacks that have different behavior.
Simply use Flint.Type and pass the :extends option which says which type module to inherit callbacks
from. This will delegate all required callbacks and any implemented optional callbacks and make them
overridable.
It also lets you make a type from an Ecto.ParameterizedType with default parameter values.
You may supply any number of default parameters. This essentially provides a new
init/1 implementation for the type, supplying the default values, while not affecting any of the
other Ecto.ParameterizedType callbacks. You may still override the newly set defaults at the local level.
Just supply all options that you wish to be defaults as extra options when using Flint.Type.
You may override any of the inherited callbacks inherity from the extended module in the case that you wish to customize the module further.
Examples
defmodule Category do
use Flint.Type, extends: Ecto.Enum, values: [:folder, :file]
endThis will apply default values to Ecto.Enum when you supply a Category type
to an Ecto schema. You may still override the values if you supply the :values
option for the field.
import Flint.Type
deftype NewUID, extends: Ecto.UUID, dump: &String.length/1This will create a new NewUID type that behaves exactly like an Ecto.UUID except it dumps
its string length.
Summary
Functions
A shorthand for creating a new Flint.Type. This is equivalent to
creating a new module with name module and calling use Flint.Type and passing opts.
Functions
A shorthand for creating a new Flint.Type. This is equivalent to
creating a new module with name module and calling use Flint.Type and passing opts.
Example
deftype Vehicle, extends: Ecto.Enum, values: [:car, :motorcycle, :truck]