View Source CozyParams.Schema.AST (cozy_params v2.1.1)
Process the AST of cozy_params.
Summary
Functions
Make sure that the AST is always a block.
Transform cozy_params supported AST to Ecto supported AST.
Extract metadata from AST.
Transpile shortcuts of embeds_one and embeds_many.
Validate if the block meets cozy_params's requirements.
Functions
Make sure that the AST is always a block.
Transform cozy_params supported AST to Ecto supported AST.
Currently, this function will:
- drop options which are supported by
cozy_paramsonly. Or, Ecto will report invalid option errors.
Extract metadata from AST.
Transpile shortcuts of embeds_one and embeds_many.
cozy_params will transpile code like following one:
embeds_one :address, required: true do
field :latitude, :float, required: true
field :longtitude, :float, required: true
endto Ecto supported code:
defmodule Address do
use CozyParams.Schema
schema do
field :latitude, :float, required: true
field :longtitude, :float, required: true
end
end
embeds_one :address, Address
Validate if the block meets cozy_params's requirements.
Although cozy_params try its best to emulate the API of Ecto.Schema, but it
doesn't mean that every API of Ecto.Schema is supported by cozy_params.
Because of that, cozy_params validates the calls before proceeding.