FileStore.Adapters.Memory (file_store v0.2.1)
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.new(
...> adapter: FileStore.Adapters.Memory,
...> base_url: "http://example.com/files/"
...> )
%FileStore{...}
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.new(adapter: FileStore.Adapters.Memory)
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.
Starts an agent for the test adapter.
Stops the agent for the test adapter.
Link to this section Functions
Link to this function
child_spec(arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
Link to this function
start_link(opts)
Starts an agent for the test adapter.
Link to this function
stop(store, reason \\ :normal, timeout \\ :infinity)
Stops the agent for the test adapter.