module Crinja::Object::Auto
Overview
When this module is included, it defines a #crinja_attribute method (see Crinja::Object for its purpose)
with dynamic accessors to all methods exposed using an annotation.
@[Crystal::Attribute](method annotation): Exposes the annotated method. Options:ignore: Don't expose this method (useful to exclude specific methods fromCrystal::Attributes)name: Expose the method under a different name.
@[Crystal::Attributes](type annotation): Exposes all methods in the annotated type. Only methods with valid signatures are exposed (can be called without arguments). Options:expose: A whitelist of methods to expose. If not defined, all methods will be exposed (unless the method itself is annotated as@[Crinja::Attribute(ignore: true)])
Example:
@[Crinja::Attributes(expose: [name, age])]
class User
include Crinja::Object::Auto
property name : String
property dob : Time
def initialize(@name, @dob)
end
def age
(Time.now - @dob).year
end
end