Alkemist v1.0.1-rc Alkemist.Utils

Provides some helper functions for the CRUD actions

Link to this section Summary

Functions

Removes any empty values from the params

Returns the default helper method for a resource to get the helper path. This can be overridden on a controller level

Returns the default helper method based on teh struct

Returns association information for a field in a resource or struct

Returns the struct name as atom

Returns the plural name for an Ecto Schema

Returns the singular name for an Ecto Schema

converts a string from lowercase with lowdashes to a readable Label

Link to this section Functions

Link to this function clean_params(params)

Removes any empty values from the params

Examples:

iex> Utils.clean_params(%{“q” => %{“title_like” => “”}, “page” => “1”}) %{“page” => “1”}

Link to this function default_resource_helper(resource)

Returns the default helper method for a resource to get the helper path. This can be overridden on a controller level

Examples

iex> Utils.default_resource_helper(Alkemist.Post) :post_path

Link to this function default_struct_helper(struct)

Returns the default helper method based on teh struct

Examples

iex> Utils.default_struct_helper(:post) :post_path

Link to this function get_association(resource, field)
get_association(map() | struct(), atom()) :: struct()

Returns association information for a field in a resource or struct

Examples:

iex> Utils.get_association(Alkemist.Category, :posts) %Ecto.Association.Has{

       cardinality: :many,
       defaults: [],
       field: :posts,
       on_cast: nil,
       on_delete: :nothing,
       on_replace: :raise,
       owner: Alkemist.Category,
       owner_key: :id,
       queryable: Alkemist.Post,
       related: Alkemist.Post,
       related_key: :category_id,
       relationship: :child,
       unique: true
     }

iex> Utils.get_association(%Alkemist.Category{}, :posts) %Ecto.Association.Has{

       cardinality: :many,
       defaults: [],
       field: :posts,
       on_cast: nil,
       on_delete: :nothing,
       on_replace: :raise,
       owner: Alkemist.Category,
       owner_key: :id,
       queryable: Alkemist.Post,
       related: Alkemist.Post,
       related_key: :category_id,
       relationship: :child,
       unique: true
     }
Link to this function get_embed(resource, field)
Link to this function get_struct(resource)

Returns the struct name as atom

Examples:

iex> Utils.get_struct(Alkemist.Post) :post

iex> Utils.get_struct(%Alkemist.Post{}) :post

Link to this function plural_name(resource)

Returns the plural name for an Ecto Schema

Examples:

iex> Utils.plural_name(%Alkemist.Post{}) “Posts”

iex> Utils.plural_name(Alkemist.Post) “Posts”

Link to this function singular_name(resource)

Returns the singular name for an Ecto Schema

Examples:

iex> Utils.singular_name(%Alkemist.Post{}) “Post”

iex> Utils.singular_name(Alkemist.Post) “Post”

converts a string from lowercase with lowdashes to a readable Label

Examples:

iex> Utils.to_label(:my_model) “My Model”

iex> Utils.to_label(“my_model”) “My Model”

iex> Utils.to_label(nil) “”