require "./database" require "./database-updater" require "./models/*" private macro define_model_getters(hash) {% for name, klass in hash %} def {{ name.id }} : {{ klass.id }} (@cache[{{ name }}] ||= {{ klass.id }}.new(self)) as {{ klass.id }} end {% end %} end module Guff class Models getter :config getter :db def initialize(@config : Config) # build model cache @cache = {} of Symbol => Model # path to db path = "%s/site.db" % [config["data"]] # update database (if necessary) DatabaseUpdater.run(path, @config) # open db @db = Database.new(path) end define_model_getters({ post: PostModel, tag: TagModel, site: SiteModel, session: SessionModel, }) end end