a love letter to tangled (android, iOS, and a search API)
1package normalize
2
3// Registry maps collection NSIDs to their adapters or state handlers.
4type Registry struct {
5 adapters map[string]RecordAdapter
6 stateHandlers map[string]StateHandler
7}
8
9// NewRegistry returns a Registry pre-loaded with all supported adapters.
10func NewRegistry() *Registry {
11 r := &Registry{
12 adapters: make(map[string]RecordAdapter),
13 stateHandlers: make(map[string]StateHandler),
14 }
15 for _, a := range []RecordAdapter{
16 &RepoAdapter{},
17 &IssueAdapter{},
18 &PullAdapter{},
19 &IssueCommentAdapter{},
20 &PullCommentAdapter{},
21 &StringAdapter{},
22 &FollowAdapter{},
23 &ProfileAdapter{},
24 } {
25 r.adapters[a.Collection()] = a
26 }
27 for _, h := range []StateHandler{
28 &IssueStateHandler{},
29 &PullStatusHandler{},
30 } {
31 r.stateHandlers[h.Collection()] = h
32 }
33 return r
34}
35
36// Adapter returns the RecordAdapter for a collection, if supported.
37func (r *Registry) Adapter(collection string) (RecordAdapter, bool) {
38 a, ok := r.adapters[collection]
39 return a, ok
40}
41
42// StateHandler returns the StateHandler for a collection, if supported.
43func (r *Registry) StateHandler(collection string) (StateHandler, bool) {
44 h, ok := r.stateHandlers[collection]
45 return h, ok
46}