struct CUID

Overview

Adds JSON support to CUID.

NOTE require "cuid/json" is required to use this feature.

require "cuid"
require "cuid/json"

class Example
  JSON.mapping id: CUID
end

example = Example.from_json(%({"id": "ck8vrqmp20000df63z8lsaahr"}))

cuid = CUID.random
cuid.to_json # => "\"ck8vrqmp20000df63z8lsaahr\""

Defined in:

cuid.cr
cuid/json.cr

Constant Summary

BASE = 36_u64
BLOCK_SIZE = 4_u64
DISCRETE_VALUES = BASE ** BLOCK_SIZE
RAND_MAX = (BASE ** RAND_SIZE) - 1
RAND_MIN = BASE ** (RAND_SIZE - 1)
RAND_SIZE = BLOCK_SIZE * 2
VERSION = "1.1.0"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(bytes : StaticArray(UInt8, 25)) #

Generates a CUID from bytes


[View source]
def self.new(slice : Slice(UInt8)) #

Generates a CUID from 16-bytes slice.


[View source]
def self.new(string : String) #

Converts a String into a CUID.


[View source]
def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.random #

Generates a random CUID


[View source]

Instance Method Detail

def inspect(io : IO) : Nil #

Convert to String in a literal format.


[View source]
def to_json(json : JSON::Builder) #

[View source]
def to_s(io : IO) : Nil #
Description copied from struct Struct

Same as #inspect(io).


[View source]