blogit v1.2.3 Blogit.RepositoryProvider behaviour View Source
A behaviour module for implementing access to remote or local repository containing files which can be used as a source for a blog and its posts.
A provider to a repository should be able to check if files exist in it, if files were updated or deleted, to check the author of a file and its dates of creation and last update. Also it should provide a way to read a file and its meta data.
A repository provider can be set for the Blogit OTP application using the
configuration key :repository_provider
. By default it is
Blogit.RepositoryProviders.Git
.
An example of implementing this behaviour could be a local folder.
When new files are added, modified and removed the
Blogit.RepositoryProvider.fetch/1
should have in its result the paths of
these files. The meta data of the file can be used as meta data
and creation and last update dates. The author of the file could be its owner.
The Blogit.RepositoryProvider
struct could contain absolute path
to the parent folder of the folder representing the repository and the
Blogit.RepositoryProvider.local_path/0
could return its name.
For now Blogit
comes with two implementations.
Blogit.RepositoryProvider.Git
provides access to Git repository and is the
default provider if none is specified in the configuration.
Blogit.RepositoryProvider.Memory
provides access to in-memory repository,
which can be used (and is used) mainly for testing purposes.
Link to this section Summary
Callbacks
Invoked to update the data represented by the given repository
to its most
recent version.
Checks if a file path is contained in the local version of the repository.
Returns file information for the file located at the given file_path
in
the given repository
. The result should be in the form of a map and should
be structured like this
Invoked to get a list of file paths of set of files contained in the locally downloaded repository.
Invoked to get the path to the locally downloaded data. If the repository is remote, it should have local copy or something like that.
Invoked in order to read the contents of the file located at the given
file_path
.
Invoked to get a representation value of the repository the provider manages. The actual data represented by this struct should be updated to its newest version first.
Link to this section Types
fetch_result()
View Sourcefetch_result() :: {:no_updates} | {:updates, [String.t()]}
file_read_result()
View Sourcefile_read_result() :: {:ok, binary()} | {:error, File.posix()}
t()
View Sourcet() :: %Blogit.RepositoryProvider{provider: provider(), repo: repository()}
Link to this section Callbacks
Invoked to update the data represented by the given repository
to its most
recent version.
If, for example the repository is remote, all the files in it should be downloaded so their most recent versions are accessible.
Returns the path to the changed files in the form of the tuple
{:updates, list-of-paths}
. These paths should be paths to deleted, updated
or newly created files.
Checks if a file path is contained in the local version of the repository.
file_info(repository, file_path)
View Sourcefile_info(repository(), file_path()) :: %{ optional(atom()) => String.t() | timestamp() }
Returns file information for the file located at the given file_path
in
the given repository
. The result should be in the form of a map and should
be structured like this:
%{
"author" => the-file-author,
"created_at" => the-date-the-file-was-created-in-iso-8601-format,
"updated_at" => the-date-of-the-last-update-of-the-file-in-iso-8601-format
}
Invoked to get a list of file paths of set of files contained in the locally downloaded repository.
Invoked to get the path to the locally downloaded data. If the repository is remote, it should have local copy or something like that.
read_file(file_path, folder)
View Sourceread_file(file_path(), folder()) :: file_read_result()
Invoked in order to read the contents of the file located at the given
file_path
.
The second parameter can be a path to a folder relative to
Blogit.RepositoryProvider.local_path/0
in which the given file_path
should
exist.
Invoked to get a representation value of the repository the provider manages. The actual data represented by this struct should be updated to its newest version first.
If for example the repository is remote, all the files in it should be downloaded so their most recent versions are accessible.
This structure can be passed to other callbacks in order to manage files in the repository.