module

Flock::Cli::Naming

Name conversions between the CLI's identifiers and Crystal's conventions.

Constants

NAME_RE = /\A[A-Za-z][A-Za-z0-9_-]*\z/

A valid identifier for a project/component/system/etc.: starts with a letter, then letters/digits/underscores/hyphens. This rejects empty names, leading digits (which would produce an invalid Crystal type like module 2048), and — importantly — path separators and .., so a name can never escape the project (see Commands::Destroy, Commands::New).

Instance methods

camel(s : String) : String

"player_health" / "player-health" / "PlayerHealth" -> "PlayerHealth" (a type name).

Source
relative_path(from : String, to : String) : String

Relative path from directory from to to (both made absolute), for requires that work regardless of where the project lives. e.g. ("/tmp/g/src", "/u/nw") -> "../../../u/nw".

Source
snake(s : String) : String

"PlayerHealth" / "player-health" -> "player_health" (a file / method name).

Source
valid_name?(s : String) : Bool
Source
validate_name!(s : String, what : String = "name") : String

Raises with an actionable message unless s is a valid identifier. what names the thing being created (e.g. "project name", "component name") for the error text.

Source