struct Amber::Configuration::SectionField

Overview

Describes one field that YAML::Serializable reads for a registered section type: its YAML key, what kind of value it holds, and, for a nested section, that section's own fields.

The AMBER_* override pass uses it to name variables, to reach fields that are nil or missing from the loaded YAML, and to turn each variable into a value of the field's type. The credentials reader uses it to read only the files a section declares. :nodoc:

Defined in:

amber/configuration/section_field.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(key : String, value_kind : Kind, list_of_fields : Array(SectionField) = [] of SectionField, entry_kind : Kind = Kind::Other) #

[View source]

Class Method Detail

def self.list_for(type : T.class, list_of_enclosing_types : Array(String) = [] of String) : Array(SectionField) forall T #

Lists the fields YAML::Serializable reads for type, honoring @[YAML::Field(key: ...)] renames and skipping ignored fields.

list_of_enclosing_types names the section types already being listed on the way down, so a section type nested inside itself is listed once along each path and listing ends.


[View source]
def self.yaml_of(instance : T) : String forall T #

Writes instance as a YAML mapping of the fields YAML::Serializable reads for its type, including fields marked ignore_serialize, so a section rebuilt from this YAML keeps the values instance holds. Nested sections are written the same way, and a nil value is written as an explicit null.

A field is written only when Amber knows how without asking the type to serialize: its value is a String, Bool, integer, float, Time or enum, an Array or Hash of the first four, or a nested YAML::Serializable section; or its converter is a type that defines its own to_yaml. Any other field is left out, and a section rebuilt from this YAML takes that field's declared default. So registering a type never requires it, or its converters, to be writable as YAML.

The writer is typed to T, so it never dispatches over every YAML::Serializable type in the program.


[View source]

Instance Method Detail

def entry_kind : Kind #

For a Hash field, the kind of each value it holds.


[View source]
def key : String #

[View source]
def list_of_fields : Array(SectionField) #

[View source]
def value_kind : Kind #

[View source]