View Source CozyParams.Schema.AST (cozy_params v1.0.1)

Process the AST of CozyParams.

Link to this section 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.

Link to this section 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_params only. Or, ecto will report invalid option errors.

Extract metadata from AST.

Link to this function

transpile_block(caller_module, arg)

View Source

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
end

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