defmodule CodeCorps.Plug.AnalyticsIdentify do
  @moduledoc """
  Plug used to identify the current user on Segment.com using `CodeCorps.Analytics.Segment`.
  """

  def init(opts), do: opts

  def call(conn, _opts) do
    if current_user = conn.assigns[:current_user] do
      CodeCorps.Analytics.Segment.identify(current_user)
      conn
    else
      conn
    end
  end
end

defmodule CodeCorps.Plug.AnalyticsIdentify do
  @moduledoc """
  Plug used to identify the current user on Segment.com using `CodeCorps.Analytics.Segment`.
  """

  def init(opts), do: opts

  def call(conn, _opts), do: conn |> identify

  defp identify(%{assigns: %{current_user: user}} = conn) do
    CodeCorps.Analytics.Segment.identify(user)
    conn
  end
  defp identify(conn), do: conn
end

Refactor AnalyticsIdentify plug to use pattern matching
Refactor AnalyticsIdentify plug to use pattern matching

Made private

code-corps/code-corps-api,crodriguez1a/code-corps-api,code-corps/code-corps-api,crodriguez1a/code-corps-api