FileStore.Adapters.Memory (file_store v0.3.0) View Source
Stores files in memory. This adapter is particularly useful in tests.
Configuration
name
- The name used to register the process.base_url
- The base URL that should be used for generating URLs to your files.
Example
iex> store = FileStore.Adapters.Memory.new(base_url: "http://example.com/files/")
%FileStore.Adapters.Memory{...}
iex> FileStore.write(store, "foo", "hello world")
:ok
iex> FileStore.read(store, "foo")
{:ok, "hello world"}
Usage in tests
defmodule MyTest do
use ExUnit.Case
setup do
start_supervised!(FileStore.Adapters.Memory)
:ok
end
test "writes a file" do
store = FileStore.Adapters.Memory.new()
assert :ok = FileStore.write(store, "foo", "bar")
assert {:ok, "bar"} = FileStore.read(store, "foo")
end
end
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Creates a new memory adapter
Starts an agent for the test adapter.
Stops the agent for the test adapter.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Specs
new(keyword()) :: FileStore.t()
Creates a new memory adapter
Starts an agent for the test adapter.
Stops the agent for the test adapter.