struct Athena::Config::AnnotationConfigurations


Wraps a hash of configuration annotations applied to a given type, method, or instance variable. Provides the logic to access each annotation's configuration in a type safe manner.

Implementations using this type must define the logic to provide the annotation hash manually; this would most likely just be something like:

# Define a hash to store the configurations.
{% custom_configurations = {} of Nil => Nil %}

# Iterate over the stored annotation classes.
{% for ann_class in ACF::CUSTOM_ANNOTATIONS %}
   {% ann_class = ann_class.resolve %}

   # Define an array to store the annotation configurations of this type.
   {% annotations = [] of Nil %}

   # Iterate over each annotation of this type on the given type, method, or instance variable.
   {% for ann in type_method_instance_variable.annotations ann_class %}
     # Add a new instance of the annotations configuration to the array.
     # Add the annotation's positional arguments first, if any, then named arguments.
     {% annotations << "#{ann_class}{ann.args.empty? ? "".id : "#{ann.args.splat},".id}#{ann.named_args.double_splat})".id %}
   {% end %}

   # Update the configuration hash with the annotation class and configuration objects, but only if there was at least one.
   {% custom_configurations[ann_class] = "(#{annotations} of ACF::AnnotationConfigurations::ConfigurationBase)".id unless annotations.empty? %}
 {% end %}

# ...

# Use the built hash to instantiate a new `ACF::AnnotationConfigurations` instance.{{custom_configurations}} of ACF::AnnotationConfigurations::Classes => Array(ACF::AnnotationConfigurations::ConfigurationBase)),

TODO Centralize the hash resolution logic once this issue is resolved.

Defined in:



Instance Method Summary

Constructor Detail

def : AnnotationHash = #

[View source]

Instance Method Detail

def has?(ann_class : ACF::AnnotationConfigurations::Classes) : Bool #

Returns true if there are annotations of the provided ann_class, otherwise false.

[View source]