struct UCL::Any

Overview

A thin, typed view over a decoded UCL::Value::Type, in the spirit of JSON::Any. Lets callers navigate and coerce values without manual casts:

cfg = UCL.load_any(File.read("app.conf"))
cfg["server"]["port"].as_i  # => 8080
cfg["server"]["hosts"].as_a # => [UCL::Any, ...]

Defined in:

ucl/any.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(raw : UCL::Value::Type) #

[View source]

Instance Method Detail

def [](key : String) : Any #

Returns the element for the object key, wrapped. Raises if the value is not an object or the key is missing.


[View source]
def [](index : Int) : Any #

Returns the element at array index, wrapped. Raises if not an array.


[View source]
def []?(key : String) : Any | Nil #

Like #[](String) but returns nil when this is not an object or the key is absent.


[View source]
def []?(index : Int) : Any | Nil #

Like #[](Int) but returns nil when this is not an array or the index is out of range.


[View source]
def as_a : Array(Any) #

Returns the array elements, each wrapped in Any. Raises if not an array.


[View source]
def as_bool : Bool #

Coerces to Bool, raising TypeCastError on a mismatch.


[View source]
def as_bool? : Bool | Nil #

Coerces to Bool?, returning nil on a mismatch.


[View source]
def as_f : Float64 #

Coerces to Float64, raising TypeCastError on a mismatch.


[View source]
def as_f? : Float64 | Nil #

Coerces to Float64?, returning nil on a mismatch.


[View source]
def as_h : Hash(String, Any) #

Returns the object entries, each value wrapped in Any. Raises if not an object.


[View source]
def as_i : Int64 #

Coerces to Int64, raising TypeCastError on a mismatch.


[View source]
def as_i? : Int64 | Nil #

Coerces to Int64?, returning nil on a mismatch.


[View source]
def as_s : String #

Coerces to String, raising TypeCastError on a mismatch.


[View source]
def as_s? : String | Nil #

Coerces to String?, returning nil on a mismatch.


[View source]
def raw : UCL::Value::Type #

The wrapped decoded value.


[View source]
def to_ucl(emit_type : String | UCL::Emitter = UCL::Encoder::DEFAULT_EMITTER) : String #

Serializes the wrapped value to UCL/JSON/YAML/MsgPack. See UCL.dump.


[View source]