Created
May 16, 2018 16:21
-
-
Save nicolasblanco/6a7d7a7784aec82e84d718f91eeb0edd 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 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