Skip to content

Commit

Permalink
Add blackhole storage
Browse files Browse the repository at this point in the history
This can be useful as a storage in cases when you do not need or want to
store cached images anywhere, for example because you have CDN in front
of the Imager and it is caching the requests.
  • Loading branch information
hauleth committed Oct 3, 2018
1 parent e514c54 commit 63b9afd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/imager/config/store_transform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Imager.Config.StoreTransform do
defp get_cache(%{cache: values}), do: parse(values)
defp get_cache(values), do: parse(values)

defp parse(%{type: type} = values) when type in ~w(S3 Local) do
defp parse(%{type: type} = values) when type in ~w(S3 Local Blackhole) do
module = Module.safe_concat(Imager.Store, type)
opts = Keyword.new(Map.get(values, :options, []))

Expand Down
12 changes: 12 additions & 0 deletions lib/imager/store/blackhole.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Imager.Store.Blackhole do
@behaviour Imager.Store

@moduledoc """
`/dev/null` of the stores. All writes will discard data and all reads
will automatically fail.
"""

def retrieve(_path, _ops), do: :error

def store(_path, _mime, stream, _opts), do: stream
end
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ defmodule Imager.Mixfile do
{:credo, ">= 0.0.0", only: [:dev], runtime: false},
{:dialyxir, ">= 0.0.0", only: [:dev], runtime: false},
{:junit_formatter, "~> 2.2", only: [:test]},
{:excoveralls, "~> 0.10", only: [:test]}
{:excoveralls, "~> 0.10", only: [:test]},
{:stream_data, "~> 0.1", only: [:test]}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"sentry": {:hex, :sentry, "7.0.0", "12421006c29d4fd6dbd822316868e542f49c934ba9bf18862304147779d4d0fc", [:mix], [{:hackney, "~> 1.8 or 1.6.5", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.3", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"statix": {:hex, :statix, "1.1.0", "af9a4586c5cd58f879e0595f06a4790878715de5b8f75f6346693aaa38da2424", [:mix], [], "hexpm"},
"stream_data": {:hex, :stream_data, "0.4.2", "fa86b78c88ec4eaa482c0891350fcc23f19a79059a687760ddcf8680aac2799b", [:mix], [], "hexpm"},
"sweet_xml": {:hex, :sweet_xml, "0.6.5", "dd9cde443212b505d1b5f9758feb2000e66a14d3c449f04c572f3048c66e6697", [:mix], [], "hexpm"},
"temp": {:hex, :temp, "0.4.5", "c62ee92c778ddebb2738212fecea372f1a9beba10bacbd7e54e7efe29357a82e", [:mix], [], "hexpm"},
"tesla": {:hex, :tesla, "1.0.0-beta.1", "5c1b5cccd20226f14720d38bd4ef07489d19798aa645e038df924c3d2a617d20", [:mix], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
Expand Down
18 changes: 18 additions & 0 deletions test/imager/store/blackhole_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Imager.Store.BlackholeTest do
use ExUnit.Case, async: true
use ExUnitProperties

alias Imager.Store.Blackhole, as: Subject

property "retreive always return error" do
check all path <- binary() do
assert :error = Subject.retrieve(path, [])
end
end

test "returns provided stream as is" do
stream = Stream.interval(10)

assert ^stream = Subject.store("", "", stream, [])
end
end

0 comments on commit 63b9afd

Please sign in to comment.