Resty v0.9.0 Resty.Resource View Source
This module provides a few functions to work with resource structs. Resource
structs are created thanks to the Resty.Resource.Base
module.
Link to this section Summary
Functions
Clone the given resource
Is the given resource new? (not persisted)
Has the given resource been persisted?
Build a URL to the resource
Build a URL to the resource
Build a URL to the resource
Link to this section Types
A resource module.
For the resource %Post{}
the resource module would be Post
A resource primary key.
A resource struct (also called a resource).
Link to this section Functions
Clone the given resource
This will create a new resource struct from the given one. The new struct will be marked as not persisted and will not have an id.
This is not deep cloning. If there are relations their ids and persisted states won’t be updated.
iex> Fakes.Post
...> |> Resty.Repo.first!()
...> |> Resty.Resource.clone()
%Fakes.Post{id: nil, name: "test1"}
Is the given resource new? (not persisted)
iex> Fakes.Post.build()
...> |> Resty.Resource.new?()
true
iex> Fakes.Post.build()
...> |> Resty.Repo.save!()
...> |> Resty.Resource.new?()
false
Has the given resource been persisted?
iex> Fakes.Post.build()
...> |> Resty.Resource.persisted?()
false
iex> Fakes.Post.build()
...> |> Resty.Repo.save!()
...> |> Resty.Resource.persisted?()
true
Build a URL to the resource.
iex> Fakes.Post |> Resty.Resource.url_for()
"site.tld/posts"
iex> Fakes.Post.build(id: 1) |> Resty.Resource.url_for()
"site.tld/posts/1"
Build a URL to the resource.
iex> Fakes.Post |> Resty.Resource.url_for(key: "value")
"site.tld/posts?key=value"
iex> Fakes.Post.build(id: 1) |> Resty.Resource.url_for(key: "value")
"site.tld/posts/1?key=value"
iex> Fakes.Post |> Resty.Resource.url_for("slug")
"site.tld/posts/slug"
Build a URL to the resource.
iex> Fakes.Post |> Resty.Resource.url_for("slug", key: "value")
"site.tld/posts/slug?key=value"