From feebbe4f8ab7ac36f86124f017e6bb4465a41306 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Fri, 4 Aug 2023 21:10:08 +0300 Subject: [PATCH] Add a generator for Link with random shorten. --- CHANGELOG.org | 2 ++ .../generators/link_with_random_shorten.ex | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 lib/link_shortener/generators/link_with_random_shorten.ex diff --git a/CHANGELOG.org b/CHANGELOG.org index 7834995..3bfc343 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -44,3 +44,5 @@ Add the CI/CD configuration. Add the test config. +** 0.5.1 <2023-08-04 Fri> + Add a generator for Link with random shorten. diff --git a/lib/link_shortener/generators/link_with_random_shorten.ex b/lib/link_shortener/generators/link_with_random_shorten.ex new file mode 100644 index 0000000..53fee85 --- /dev/null +++ b/lib/link_shortener/generators/link_with_random_shorten.ex @@ -0,0 +1,14 @@ +defmodule LinkShortener.Generators.LinkWithRandomShorten do + @moduledoc """ + This module provides a generator for Link. + """ + + alias LinkShortener.Generators.SafeString + + @doc """ + Generate a Link with random shorten with the length. + """ + def generate_one(attrs, length \\ 10, generator \\ &SafeString.generate/1) do + Map.put(attrs, :shorten, generator.(length)) + end +end