(patch) Pre-commit and builds
All checks were successful
/ Build and Release Library (push) Successful in 1m15s

This commit is contained in:
Pat Garrity 2024-03-24 04:02:38 +00:00
parent cfcbfdfdac
commit c3cb5502e8
5 changed files with 40 additions and 19 deletions

View file

@ -26,7 +26,7 @@ jobs:
pre-commit run --all-files
- name: 'Prepare Versioned Build'
run: |
latest_git_tag="$(git describe --tags --abbrev=0)"
latest_git_tag="$(git describe --tags --abbrev=0 || echo 'No Tags')"
latest_commit_message="$(git show -s --format=%s HEAD)"
if [[ "$latest_commit_message" == *"(major)"* ]]; then
export GS_RELEASE_TYPE="major"

View file

@ -27,7 +27,7 @@ jobs:
pre-commit run --all-files
- name: 'Prepare Versioned Build'
run: |
latest_git_tag="$(git describe --tags --abbrev=0)"
latest_git_tag="$(git describe --tags --abbrev=0 || echo 'No Tags')"
latest_commit_message="$(git show -s --format=%s HEAD)"
if [[ "$latest_commit_message" == *"(major)"* ]]; then
export GS_RELEASE_TYPE="major"

View file

@ -17,3 +17,23 @@ externalResolvers +=
val GsSlug: ModuleID =
"gs" %% "gs-slug-v0" % "0.1.0"
```
## Slug Type
`Slug` is the type exposed by this library. It is an extremely small,
restricted, opaque type (`String`) that adheres to the following regular
expression:
```
^[a-z0-9]+(?:\-[a-z0-9]+)*$
```
This type is intended for use in the following scenarios:
- Restricted ASCII is acceptable.
- URL safety is desired.
Additionally, `Slug` is usually intended to be unique within some _context_,
where the implementation defines the context. For example, if some organization
owns a number of repositories, each repository might have a `Slug` which is
unique within that organization.

View file

@ -2,16 +2,15 @@ package gs.slug.v0
import scala.util.matching.Regex
/**
* Restricted string intended to be used as a unique, URL-safe identifier
/** Restricted string intended to be used as a unique, URL-safe identifier
* within some specific context (not a globally unique identifier). This type
* adheres to the regular expression: `^[a-z0-9]+(?:\-[a-z0-9]+)*$`
*
* Essentially, Slugs follow these rules:
*
* - Segments are defined as lowercase alphanumeric ASCII strings.
* - Segments are separated by exactly one `-` character.
* - At least one segment is required.
* - Segments are defined as lowercase alphanumeric ASCII strings.
* - Segments are separated by exactly one `-` character.
* - At least one segment is required.
*
* If you need full unicode support, more characters, fewer constraints, etc.
* don't use this type.
@ -22,21 +21,22 @@ object Slug:
val SlugPattern: Regex = "^[a-z0-9]+(?:\\-[a-z0-9]+)*$".r
/**
* Instantiate a [[Slug]] by validating the candidate input.
*
* @param candidate The candidate string used to create the [[Slug]].
* @return The [[Slug]], or `None` if the candidate is invalid.
*/
def validate(candidate: String): Option[Slug] =
/** Instantiate a [[Slug]] by validating the candidate input.
*
* @param candidate
* The candidate string used to create the [[Slug]].
* @return
* The [[Slug]], or `None` if the candidate is invalid.
*/
def validate(candidate: String): Option[Slug] =
if SlugPattern.matches(candidate) then Some(candidate) else None
given CanEqual[Slug, Slug] = CanEqual.derived
extension (slug: Slug)
/**
* Render this [[Slug]] as a string.
*
* @return The string representation of this [[Slug]].
*/
/** Render this [[Slug]] as a string.
*
* @return
* The string representation of this [[Slug]].
*/
def str(): String = slug

View file

@ -1,6 +1,7 @@
package gs.slug.v0
class SlugTests extends munit.FunSuite:
test("should instantiate valid slugs") {
('a' to 'z').foreach(c => assertValidSlug(c.toString()))
('0' to '9').foreach(c => assertValidSlug(c.toString()))