forked from superbobry/io-docs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MetaCache.io
47 lines (43 loc) · 1.46 KB
/
MetaCache.io
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
39
40
41
42
43
44
45
46
47
# Container object for all of the parsed information, where keys
# are object names (extracted from `metadoc <ObjectName>` comments)
# and values are Meta objects.
#
# MetaCache is indexable two ways:
# by object names through squareBrackets
# MetaCache["UnitTest"] ==> Meta(...)
# by category through curlyBrackets
# MetaCache{"Testing"} ==> list(Meta(...), Meta(...))
MetaCache := Map clone do(
# MetaCache is a singleton, which means cloning has no effect.
clone := lazySlot(self)
# MetaCache isn't designed to be modified after it's initially
# populated by DocExtractor, hence, categories should be better
# made a lazySlot, instead of a plain method(), but that would
# make the testing really complicated.
categories := method(
self values map(category) unique sort
)
modules := method(
self values map(module) unique sort remove("")
)
# Returns cache subset for a given category or a reference to
# MetaCache if no category is given.
curlyBrackets := method(category,
if(category,
self select(k, v, v category == category)
,
self
)
)
squareBrackets := method(object,
# Looking up the Meta object in the cache, if it doesn't exist,
# creating a new one.
meta := at(object)
meta ifNil(
meta := Meta clone
meta object := object
atPut(object, meta)
)
meta
)
)