resx v0.1.0 Resx.Storer behaviour

A storer is an interface to perform some side-effect with a resource.

While this is intended for things such as caching, or saving a resource at some destination. It may also be used for producing other side-effects such as logging, delivery/dispatch, etc.

A store by itself is not referenceable, due to this it is suggested that the store should not modify the resource, as this is likely to lead to confusion when obtaining and passing around references. The suggested way of implementing a referenceable store, is to have the store implement the Resx.Producer behaviour as well. An example of this is the default file handler Resx.Producers.File, this is both a producer and a store.

Link to this section Summary

Functions

Save a resource in the target store

Save a resource in the target store

Callbacks

Optionally implement the behaviour to discard a resource. This should be used to reverse the effects of a store. The default implementation does nothing and just returns :ok

Implement the behaviour to store a resource

Link to this section Functions

Link to this function save!(resource, storer, opts \\ [])

Save a resource in the target store.

Raises a Resx.Storer.StoreError if the resource couldn't be stored.

For more details see save/3.

Link to this function save(resource, storer, opts \\ [])
save(Resx.Resource.t(), module(), keyword()) ::
  {:ok, Resx.Resource.t()} | Resx.error()

Save a resource in the target store.

A storer must be a module that implements the Resx.Storer behaviour.

Link to this section Callbacks

Link to this callback discard(reference, options)
discard(reference :: Resx.ref(), options :: keyword()) ::
  :ok | Resx.error(Resx.resource_error() | Resx.reference_error())

Optionally implement the behaviour to discard a resource. This should be used to reverse the effects of a store. The default implementation does nothing and just returns :ok.

The options keyword allows for your implementation to expose some configurable settings.

If the resource was successfully discarded return :ok. Otherwise return an appropriate error.

Link to this callback store(resource, options)
store(resource :: Resx.Resource.t(), options :: keyword()) ::
  {:ok, resource :: Resx.Resource.t()} | Resx.error()

Implement the behaviour to store a resource.

The options keyword allows for your implementation to expose some configurable settings.

If the store was successful return { :ok, resource }, where resource is the stored resource. Otherwise return an appropriate error.