Skip to content

v1.2.0

Constructor helper method.

With the v1.2.0 Crygen's release, you can easily add the constructor by calling the #add_initialize helper method.

Crygen::Types::Class.new("Person").add_initialize do |method|
  method.add_arg("@x", "Int32")
  method.add_arg("@y", "Int32")
end

With the example code above, it is possible to configure the method for adding the arguments and write the body. The block is not required for adding the constructor.

Generate nested classes and structs

Also, this version provides the new feature for adding the class in the class or the struct in the struct.

person_class = Crygen::Types::Class.new("Person")

puts person_class.add_class(person_class)

Output:

class Person
  class Person
  end
end
point_struct = Crygen::Types::Struct.new("Point")

puts point_struct.add_class(point_struct)

Output:

struct Point
  struct Point
  end
end

Warning

For the moment, it is not possible to add a struct in a class and vice versa. If you need this feature for your project, don't hesitate to create an issue on Github.

Add annotations onto properties, getters and setters

my_annotation = CGT::Annotation.new("JSON::Field").add_arg("key", "full_name".dump)
Crygen::Types::Class.new("Person").add_property(
  :property, "name", "String", annotations: [my_annotation]
)
class Person
  @[JSON::Field(key: "full_name")]
  property name : String
end