Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows skipping files during the transformation #208

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/arc/actions/store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ defmodule Arc.Actions.Store do
defp put_version(definition, version, {file, scope}) do
case Arc.Processor.process(definition, version, {file, scope}) do
{:error, error} -> {:error, error}
{:skip} -> {:skip}
{:ok, file} ->
file_name = Arc.Definition.Versioning.resolve_file_name(definition, version, {file, scope})
file = %Arc.File{file | file_name: file_name}
Expand Down
1 change: 1 addition & 0 deletions lib/arc/processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Arc.Processor do

defp apply_transformation(file, :noaction), do: {:ok, file}
defp apply_transformation(file, {:noaction}), do: {:ok, file} # Deprecated
defp apply_transformation(_file, :skip), do: {:skip}
defp apply_transformation(file, {cmd, conversion, _}) do
apply_transformation(file, {cmd, conversion})
end
Expand Down
15 changes: 15 additions & 0 deletions test/actions/store_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ defmodule ArcTest.Actions.Store do
def __versions, do: [:original, :thumb]
end

defmodule SkipFileDummyDefinition do
use Arc.Actions.Store
use Arc.Definition.Storage

def validate(_), do: true
def transform(_, _), do: :skip
def __versions, do: [:original, :thumb]
end

test "checks file existance" do
assert DummyDefinition.store("non-existant-file.png") == {:error, :invalid_file_path}
end
Expand Down Expand Up @@ -50,6 +59,12 @@ defmodule ArcTest.Actions.Store do
end
end

test "skip file does not try to store it" do
with_mock Arc.Storage.S3, [put: fn(SkipFileDummyDefinition, _, {%{file_name: "image.png", path: @img}, :scope}) -> {:error, {:http_error, 404, "XML"}} end] do
assert SkipFileDummyDefinition.store({%{filename: "image.png", path: @img}, :scope}) == {:ok, "image.png"}
end
end

test "timeout" do
Application.put_env :arc, :version_timeout, 1

Expand Down