Last active
February 26, 2016 17:40
-
-
Save tokafish/b17a9a78bf9b188c874f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Phoenix.Ecto.SQL.Sandbox do | |
# ... | |
def call(conn, sandbox) do | |
conn |> fetch_cookies |> allow_sandbox_access(sandbox) | |
end | |
defp allow_sandbox_access(%{req_cookies: %{@cookie_name => configuration}} = conn, sandbox) do | |
[pid_string,repo_string] = configuration |> URI.decode |> String.split("|") | |
owner = to_pid(pid_string) | |
repo = String.to_atom(repo_string) | |
Ecto.Adapters.SQL.Sandbox.allow(repo, owner, self()) | |
conn | |
end | |
defp allow_sandbox_access(conn, _sandbox), do: conn | |
defp to_pid(string) do | |
string |> String.to_char_list |> :erlang.list_to_pid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment