MapSchema.Examples.CustomTypeLang (map_schema v0.2.6) View Source
MapSchema.Examples.CustomTypeLang
Imagine here a query to Database or any place where you have the list https://www.iso.org/iso-639-language-codes.html https://es.wikipedia.org/wiki/ISO_639-1 only if the value exist it will be valid in other case the schema wont be valid. It´s simple. ;)
Link to this section Summary
Functions
We are interesting in that every string will be lowcase. then it´s simple we add in the cast a function that make downcase.
Stop... the magic continue. After define our cast and validation functions we can define a generador of doctest... Yes ¡¡ You are reading well.. TEST FREE¡¡
In this example our database it´s a simple list with ["zh", "en", "es"]
Callback implementation for MapSchema.CustomType.name/0
.
Callback implementation for MapSchema.CustomType.nested?/0
.
Link to this section Functions
Specs
We are interesting in that every string will be lowcase. then it´s simple we add in the cast a function that make downcase.
Examples
iex> alias MapSchema.Examples.CustomTypeLang iex> CustomTypeLang.cast("ES") ...> |> CustomTypeLang.is_valid?() true
iex> alias MapSchema.Examples.CustomTypeLang iex> CustomTypeLang.cast(nil) :error
Specs
Stop... the magic continue. After define our cast and validation functions we can define a generador of doctest... Yes ¡¡ You are reading well.. TEST FREE¡¡
If you define this function well... you can have a fast test of your new datatype ;)
This method return a list of tuples [{value_test, expected_value},{.. , ..}...] map schema selected a random tuple for build the test ;) Please be careful, and test that every tuple it´s correct. Thanks.
It´s important be careful because the values should be in string format for can be writed
in the doctest please review that mix docs
run without problems.
Examples
iex> alias MapSchema.Examples.CustomTypeLang
iex> CustomTypeLang.doctest_values()
[{"\"zh\"", "\"zh\""}, {"\"en\"", "\"en\""}, {"\"es\"", "\"es\""}]
Specs
In this example our database it´s a simple list with ["zh", "en", "es"]
Examples
iex> alias MapSchema.Examples.CustomTypeLang
iex> CustomTypeLang.is_valid?("zh")
true
iex> CustomTypeLang.is_valid?("en")
true
iex> CustomTypeLang.is_valid?("es")
true
iex> alias MapSchema.Examples.CustomTypeLang
iex> CustomTypeLang.is_valid?("ES")
false
iex> alias MapSchema.Examples.CustomTypeLang
iex> CustomTypeLang.is_valid?("Español")
false
Specs
name() :: atom()
Callback implementation for MapSchema.CustomType.name/0
.
Callback implementation for MapSchema.CustomType.nested?/0
.