View Source Flint.Partial (Flint v0.2.1)

Flint.Partial 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.Partial 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.Partial.

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.Partial, extends: Ecto.Enum, values: [:folder, :file]
end

This 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.

Summary

Functions

A shorthand for creating a new module to represent a partial Ecto.ParameterizedType. This is equivalent to creating a new module with name module and calling use Flint.Partial and passing opts.

Functions

Link to this function

defpartial(module, opts)

View Source

A shorthand for creating a new module to represent a partial Ecto.ParameterizedType. This is equivalent to creating a new module with name module and calling use Flint.Partial and passing opts.

Practially speaking, this is only really useful for defining default values for an Ecto.ParameterizedType with no changes to any of the other callbacks.

Example

defpartial Vehicle, extends: Ecto.Enum, values: [:car, :motorcycle, :truck]