blogit v1.2.1 Blogit.RepositoryProviders.Memory View Source

This module implements the Blogit.RepositoryProvider behaviour.

It provides in-memory repository access which can be used for testing.

The repository is just an Agent process, so messages could be sent to it in order to add or remove data to or from it.

Link to this section Summary

Functions

Stores a file in the in-memory repository. Returns the state of the in-memory repository before the addition

Adds a file to the in-memory repository using the given file_path as path to the file to create and the given data as its contents

Deletes a file from the in-memory repository. Returns the state of the repository before the modification

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:

%{
  "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

Invoked in order to read the contents of the file located at the given file_path

Replaces an existing file’s content with new content. If the file doesn’t exist, creates it. Returns the state of the repository before the modification

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

Starts the memory repository as a process. The process is named and its name is the name of this module

Stops the in-memory repository process

Link to this section Types

Link to this section Functions

Link to this function add_file(file) View Source
add_file(Blogit.RepositoryProviders.Memory.File.t) :: t

Stores a file in the in-memory repository. Returns the state of the in-memory repository before the addition.

Link to this function add_file(file_path, data) View Source
add_file(String.t, term) :: t

Adds a file to the in-memory repository using the given file_path as path to the file to create and the given data as its contents.

Returns the state of the repository before the modification.

Link to this function delete_file(file_path) View Source
delete_file(String.t) :: t

Deletes a file from the in-memory repository. Returns the state of the repository before the modification.

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.

Callback implementation for Blogit.RepositoryProvider.fetch/1.

Checks if a file path is contained in the local version of the repository.

Callback implementation for Blogit.RepositoryProvider.file_in?/1.

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
}

Callback implementation for Blogit.RepositoryProvider.file_info/2.

Invoked to get a list of file paths of set of files contained in the locally downloaded repository.

Callback implementation for Blogit.RepositoryProvider.list_files/1.

Invoked to get the path to the locally downloaded data. If the repository is remote, it should have local copy or something like that.

Callback implementation for Blogit.RepositoryProvider.local_path/0.

Link to this function read_file(file_name, folder \\ "") View Source

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.

Callback implementation for Blogit.RepositoryProvider.read_file/2.

Link to this function replace_file(file) View Source
replace_file(Blogit.RepositoryProviders.Memory.File.t) :: t

Replaces an existing file’s content with new content. If the file doesn’t exist, creates it. Returns the state of the repository before the modification.

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.

Callback implementation for Blogit.RepositoryProvider.repository/0.

Link to this function start_link(data \\ %Blogit.RepositoryProviders.Memory{}) View Source
start_link(t) :: {:ok, pid} | {:error, term}

Starts the memory repository as a process. The process is named and its name is the name of this module.

Accepts argument of type Blogit.RepositoryProviders.Memory.t. By default the repository is empty.

Stops the in-memory repository process.