module Athena::Config

Overview

Athena's Config component contains common types for configuring a component.

The main types include:

See each specific type for more detailed information.

Defined in:

annotation_configurations.cr
athena-config.cr

Constant Summary

CONFIG_PATH_NAME = "ATHENA_CONFIG_PATH"

The name of the environment variable that stores the path to the configuration file.

DEFAULT_CONFIG_PATH = "./athena.yml"

The default path to the configuration file.

Class Method Summary

Macro Summary

Class Method Detail

def self.config : ACF::Base #

Returns the ACF::Base object instantiated from the configuration file located at .config_path.

The contents of the configuration file are included into the binary at compile time so that the file itself does not need to be present for the binary to run. The configuration string is not processed until .config is called for the first time so that in the future it will respect ENV vars for the environment the binary is in.

TODO Handle resolving ENV vars and DI parameters within the configuration file.


[View source]
def self.config_path : String #

Returns the current path that the configuration file is located at.

Falls back on DEFAULT_CONFIG_PATH if a ATHENA_CONFIG_PATH ENV variable is not defined.


[View source]

Macro Detail

macro configuration_annotation(name, *args, &) #

Registers a configuration annotation with the provided name. Defines a configuration record with the provided args, if any, that represents the possible arguments that the annotation accepts. May also be used with a block to add custom methods to the configuration record.

Example

# Defines an annotation without any arguments.
ACF.configuration_annotation Secure

# Defines annotation with a required and optional argument.
# The default value will be used if that key isn't supplied in the annotation.
ACF.configuration_annotation SomeAnn, id : Int32, debug : Bool = true

# A block can be used to define custom methods on the configuration object.
ACF.configuration_annotation CustomAnn, first_name : String, last_name : String do
  def name : String
    "#{@first_name} #{@last_name}"
  end
end

NOTE The logic to actually do the resolution of the annotations must be handled in the owning shard. Athena::Config only defines the common logic that each implementation can use. See ACF::AnnotationConfigurations for more information.


[View source]