blob: 52437d4ad6cc3e010e438d7cb5f7a593d9d9105f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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,
})
end
end
|