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
Removes any empty values from the params
Examples:
iex> Utils.clean_params(%{“q” => %{“title_like” => “”}, “page” => “1”}) %{“page” => “1”}
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
Returns the default helper method based on teh struct
Examples
iex> Utils.default_struct_helper(:post) :post_path
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
}
Returns the struct name as atom
Examples:
iex> Utils.get_struct(Alkemist.Post) :post
iex> Utils.get_struct(%Alkemist.Post{}) :post
Returns the plural name for an Ecto Schema
Examples:
iex> Utils.plural_name(%Alkemist.Post{}) “Posts”
iex> Utils.plural_name(Alkemist.Post) “Posts”
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) “”