dd v0.0.3 DD.Type.Id
Link to this section Summary
Functions
Convert a string external representation of a value into into it’s internal representation
A record is defined using something like
Convert a value to a string that will be suitable for display (for example as the value of an tag
Validates that the given value is consistent with a type and that it obeys any constraints in it’s specs
Link to this section Functions
Convert a string external representation of a value into into it’s internal representation
Callback implementation for DD.Type.Behaviour.from_display_value/2
.
A record is defined using something like
defrecord Person do
string(:name, min: 2, max: 50)
date(:dob)
end
The defrecord
code calls the type module’s from_spec
function
for each field (so the type modules DD.Type.String and
DD.Type.Date would be called about).
This function returns a field definition structure, having first validated (and possibly manipulated) the arguments.
In the first example above, from_spec
would we called with
DD.String.from_options(:name, [ min: 2, max: 50 ])
Values that are stored in the field structure have potentially been
updated to work with this type. For example, if you pass a string as
an option to DD.Type.String’s matches:
option, it will be returned
as a Regex.
Callback implementation for DD.Type.Behaviour.from_options/2
.
Convert a value to a string that will be suitable for display (for example as the value of an tag.
Callback implementation for DD.Type.Behaviour.to_display_value/2
.
Validates that the given value is consistent with a type and that it obeys any constraints in it’s specs.
For example, the validation for DD.Type.String is:
def validate(value, _) when not is_binary(value) do
"should be a string"
end
def validate(value, specs) do
validate_length(String.length(value), specs[:min], specs[:max])
|| validate_matches(value, specs[:matches])
end
Callback implementation for DD.Type.Behaviour.validate/2
.