class Envcat::Check

Defined in:

envcat/check.cr

Constant Summary

CONSTRAINTS = {presence: ->(v : String | ::Nil, _a : Array(String)) do (v && (!v.empty?)) || "must be defined" end, alnum: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_ALNUM.match(v))) || "must be alphanumeric" end, b64: ->(v : String | ::Nil, _a : Array(String)) do ((v && ((v.size % 4) === 0)) && ((/^[a-zA-Z0-9+\/]+={0,2}$/) =~ v)) || "must be base64" end, f: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_UFLOAT.match(v))) || "must be an unsigned float" end, fs: ->(v : String | ::Nil, _a : Array(String)) do (v && (File.exists?(v))) || "must be a path to an existing file or directory" end, fsd: ->(v : String | ::Nil, _a : Array(String)) do (v && (File.directory?(v))) || "must be a path to an existing directory" end, fsf: ->(v : String | ::Nil, _a : Array(String)) do (v && (File.file?(v))) || "must be a path to an existing file" end, gt: ->(v : String | ::Nil, a : Array(String)) do (v && v.to_f > a[0].to_f) || "must be > #{a[0]}" end, gte: ->(v : String | ::Nil, a : Array(String)) do (v && v.to_f >= a[0].to_f) || "must be >= #{a[0]}" end, hex: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_HEX.match(v))) || "must be a hex number" end, hexcol: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_HEXCOLOR.match(v))) || "must be a hex color" end, i: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_UINT.match(v))) || "must be an unsigned integer" end, ip: ->(v : String | ::Nil, _a : Array(String)) do (v && (Socket::IPAddress.valid?(v))) || "must be an ip address" end, ipv4: ->(v : String | ::Nil, _a : Array(String)) do (v && (Socket::IPAddress.valid_v4?(v))) || "must be an ipv4 address" end, ipv6: ->(v : String | ::Nil, _a : Array(String)) do (v && (Socket::IPAddress.valid_v6?(v))) || "must be an ipv6 address" end, json: ->(v : String | ::Nil, _a : Array(String)) do begin (v && (JSON.parse(v))) || (raise("")) rescue "must be JSON" end end, lc: ->(v : String | ::Nil, _a : Array(String)) do (v && (v.downcase === v)) || "must be all lowercase" end, len: ->(v : String | ::Nil, a : Array(String)) do ((v && v.size >= a[0].to_i) && v.size <= a[1].to_i) || "must be #{a[0]}-#{a[1]} characters" end, lt: ->(v : String | ::Nil, a : Array(String)) do (v && v.to_f < a[0].to_f) || "must be < #{a[0]}" end, lte: ->(v : String | ::Nil, a : Array(String)) do (v && v.to_f <= a[0].to_f) || "must be <= #{a[0]}" end, n: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_UFLOAT.match(v))) || "must be an unsigned float or integer" end, nre: ->(v : String | ::Nil, a : Array(String)) do (v && (!((Regex.new(a.join(":"))).match(v)))) || "must not match PCRE regex: #{a.same?(DUMMY_ARGS) ? a[0] : a.join(":")}" end, port: ->(v : String | ::Nil, _a : Array(String)) do (((v && (RX_INT.match(v))) && v.to_i >= 0) && v.to_i <= 65535) || "must be a port number (0-65535)" end, re: ->(v : String | ::Nil, a : Array(String)) do (v && ((Regex.new(a.join(":"))).match(v))) || "must match PCRE regex: #{a.same?(DUMMY_ARGS) ? a[0] : a.join(":")}" end, sf: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_NUM.match(v))) || "must be a float" end, si: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_INT.match(v))) || "must be an integer" end, sn: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_NUM.match(v))) || "must be a float or integer" end, uc: ->(v : String | ::Nil, _a : Array(String)) do (v && (v.upcase === v)) || "must be all uppercase" end, uuid: ->(v : String | ::Nil, _a : Array(String)) do (v && (RX_UUID.match(v))) || "must be a UUID" end, v: ->(v : String | ::Nil, _a : Array(String)) do begin (v && (SemanticVersion.parse(v))) || (raise("")) rescue "must be a semantic version" end end, vgt: ->(v : String | ::Nil, a : Array(String)) do begin (v && (SemanticVersion.parse(v)) > (SemanticVersion.parse(a[0]))) || (raise("")) rescue "must be a semantic version > #{a[0]}" end end, vgte: ->(v : String | ::Nil, a : Array(String)) do begin (v && (SemanticVersion.parse(v)) >= (SemanticVersion.parse(a[0]))) || (raise("")) rescue "must be a semantic version >= #{a[0]}" end end, vlt: ->(v : String | ::Nil, a : Array(String)) do begin (v && (SemanticVersion.parse(v)) < (SemanticVersion.parse(a[0]))) || (raise("")) rescue "must be a semantic version < #{a[0]}" end end, vlte: ->(v : String | ::Nil, a : Array(String)) do begin (v && (SemanticVersion.parse(v)) <= (SemanticVersion.parse(a[0]))) || (raise("")) rescue "must be a semantic version <= #{a[0]}" end end}
DUMMY_ARGS = ["X", "Y", ".."] of ::String
EXCLUDE_FROM_HELP = [:presence] of ::Symbol
RX_ALNUM = /^[a-zA-Z0-9]+$/
RX_HEX = /^(0x|0h)?[0-9A-F]+$/i
RX_HEXCOLOR = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i
RX_INT = /^[-]?\d+$/
RX_NUM = /^[-]?([0-9]*[.])?[0-9]+$/
RX_UFLOAT = /^([0-9]*[.])?[0-9]+$/
RX_UINT = /^\d+$/
RX_UUID = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i

Class Method Summary

Class Method Detail

def self.help_for(io, constraint_id) #

[View source]
def self.invalid?(env, var_name, constraint_id, args : Array(String), permit_undefined = false) #

[View source]