module Totem::ConfigBuilder

Overview

Builder of Configuration

Load config

struct Config
  include Totem::ConfigBuilder

  build do
    config_type "yaml"
    config_paths ["/etc", "~/.config/totem", "config"]
  end
end

config = Config.configure
config["name"] # => "foo"

Load config with custom file

struct Config
  include Totem::ConfigBuilder

  build do
    config_type "yaml"
    config_paths ["/etc", "~/.config/totem", "config"]
  end
end

config = Config.configure("/path/to/config/config.example.json")
config["name"] # => "foo"

Load config and mapping to struct

struct Profile
  include Totem::ConfigBuilder

  property name : String
  property gender : String

  build do
    config_type "yaml"
    config_paths ["/etc", "~/.config/totem", "config/"]
  end
end

config = Profile.configure do |c|
  c.set_default("gender", "unkown")
end

config.name     # => "foo"
config.gender   # => "unkown"
config["title"] # => "bar"

Defined in:

totem/config_builder.cr

Macro Summary

Macro Detail

macro build #

Build block


[View source]