class

Artistry::Registry

Inherits Reference < Object

Constants

CODE_FORMAT = /\A[A-Z]{1,2}\z/
FIELD_FORMAT = /\A[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)*\z/

A field an index can name: letters, digits, _ and -, starting with a letter or _, with . between the names of nested fields (meta.author).

Constructors

new(code : String, kind : String, plugin : String, description : Nil | String, symbol : Nil | String, version : Int32)
Source

Class methods

add_index(kind : String, fields : Array(String), *, plugin : String) : Index

Ask for an index on a kind's fields, in order, for plugin's common lookups: Artifact.where fixing the leading fields (or all of them) then reads one range of the index instead of every artifact of the kind. Any plugin may ask, for any kind, given by code or name.

Indexes are shared: asking for fields already indexed records plugin as wanting the index too, and it stays until every plugin that asked has dropped it (drop_index). They cover current versions only, so where(..., include_superseded: true) doesn't use them. Raises InvalidIndex.

Source
add_index(kind : String, field : String, *, plugin : String) : Index

Ask for an index on a kind's fields, in order, for plugin's common lookups: Artifact.where fixing the leading fields (or all of them) then reads one range of the index instead of every artifact of the kind. Any plugin may ask, for any kind, given by code or name.

Indexes are shared: asking for fields already indexed records plugin as wanting the index too, and it stays until every plugin that asked has dropped it (drop_index). They cover current versions only, so where(..., include_superseded: true) doesn't use them. Raises InvalidIndex.

Source
all

List all registrations

Source
allocate_code(db, kind : String) : String

Allocate a free one- or two-letter code for a kind name.

Tries the first letter, then the first letter followed by each later letter of the name, then the first letter followed by A-Z. Codes are capped at two letters because slugs ("C42", "42C") are parsed that way.

Source
drop_index(kind : String, fields : Array(String), *, plugin : String) : Bool

Withdraw plugin's claim on the index over fields, and drop the index once no plugin claims it. Returns whether plugin had claimed it.

Source
drop_index(kind : String, field : String, *, plugin : String) : Bool

Withdraw plugin's claim on the index over fields, and drop the index once no plugin claims it. Returns whether plugin had claimed it.

Source
find(plugin : String, kind : String) : Registry | Nil

Lookup a registration by plugin and kind

Source
find(code : String) : Registry | Nil

Lookup a registration by code

Source
find_by_kind(kind : String) : Registry | Nil

Lookup a registration by kind name only (returns first match if multiple plugins use same kind)

Source
get_schema(code : String, version : Int32) : JSON::Any | Nil

Get the schema JSON for a code and version

Source
hash_schema(json : String) : String
Source
indexes(kind : String) : Array(Index)

A kind's indexes, each with the plugins that asked for it.

Source
normalize_schema(schema) : String
Source
register(kind : String, plugin : String, schema, description : String | Nil = nil, symbol : String | Nil = nil, index : Array = [] of String, code : String | Nil = nil) : String

Register a new artifact kind. Returns the assigned code. Schema is a JSON Schema as any JSON-serializable value. Raises InvalidSchema if it can't be parsed, so it fails here rather than on every create. index lists the indexes this plugin asks for on the kind, as add_index does: each entry a field or an ordered list of fields (["title", ["voice", "bit"]]). Leaving one out later doesn't drop it; drop_index does.

code declares the kind's code (one or two uppercase letters) so it doesn't depend on registration order. Without it, a code is allocated from the kind name. Raises InvalidCode, CodeConflict (another kind owns the code) or CodeMismatch (this kind is already registered under a different code).

Source

Instance methods

code
Source
description
Source
kind
Source
plugin
Source
symbol
Source
version
Source

Nested types