class Crygen::Types::Annotation

Overview

A class that allows to generate an annotation.

class_type = CGT::Class.new("Person")
class_type.add_annotation(CGT::Annotation.new("Experimental"))
puts class_type.generate

Output:

@[Experimental]
class Person
end

Defined in:

types/annotation.cr

Constructors

Instance Method Summary

Instance methods inherited from class Crygen::Abstract::GeneratorInterface

generate : String generate

Constructor Detail

def self.new(name : String) #

[View source]

Instance Method Detail

def add_arg(name : String, value : String) : self #

Adds a name and value into the argument.

annotation_type = Crygen::Types::Annotation.new("MyAnnotation")
annotation_type.add_arg("full_name", "John Doe".dump)

Output:

@[MyAnnotation(full_name: "John Doe")]

Returns: an object class itself.


[View source]
def add_arg(value : String) : self #

Adds only a value into the argument.

annotation_type = Crygen::Types::Annotation.new("MyAnnotation")
annotation_type.add_arg("true")

Output:

@[MyAnnotation(true)]

Returns: an object class itself.


[View source]
def generate : String #

Generates an annotation. Returns: String


[View source]