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 Plug.Anonymous do | |
import Plug.Conn | |
require IEx | |
def init(options), do: options | |
def call(conn, _opts) do | |
anonymous_id = get_session(conn, :anonymous_id) | |
case anonymous_id do |
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 Plug.AnonymousSessionStore do | |
@behaviour Plug.Session.Store | |
def init(_opts) do | |
nil | |
end | |
def get(_conn, sid, nil) do | |
{sid, Process.get({:session, sid}) || %{}} | |
end |
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 Plug.AnonymousTest do | |
use ExUnit.Case, async: true | |
use Plug.Test | |
require IEx | |
alias Plug.AnonymousSessionStore | |
test "assigns user_id session key" do | |
# opts = Anonymous.init([]) | |
conn = conn(:get, "/") |> fetch_session |
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
## | |
# first run `brew install terminal-notifier` | |
# then save this file in your home directory | |
# and source it in your env file | |
# e.g if you're using zsh, you'd add this in your .zshrc: | |
# source $HOME/make-rake-talk.sh | |
# | |
# Restart your terminal and you no longer need to keep | |
# staring at the screen when you're doing long ass rake tasks | |
# |
NewerOlder