Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Created May 16, 2018 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolasblanco/6a7d7a7784aec82e84d718f91eeb0edd to your computer and use it in GitHub Desktop.
Save nicolasblanco/6a7d7a7784aec82e84d718f91eeb0edd to your computer and use it in GitHub Desktop.
defmodule EctoAutoslugField.ForceSlugGeneration do
alias EctoAutoslugField.SlugBase
defmacro __using__(_opts) do
quote do
def force_generate_slug(changeset) do
opts = [
from: @from,
to: @to,
always_change: true,
slug_builder: &build_slug/2
]
sources = if opts[:from] == nil do
get_sources(changeset, opts)
else
@from
end
SlugBase.maybe_generate_slug(changeset, sources, opts)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment