generated from snivilised/astrolib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extent.go
127 lines (104 loc) Β· 2.6 KB
/
extent.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package age
import (
"github.com/snivilised/agenor/core"
"github.com/snivilised/agenor/enums"
"github.com/snivilised/agenor/internal/enclave"
"github.com/snivilised/agenor/internal/feat/resume"
"github.com/snivilised/agenor/internal/kernel"
"github.com/snivilised/agenor/internal/opts"
"github.com/snivilised/agenor/internal/third/lo"
"github.com/snivilised/agenor/pref"
"github.com/snivilised/agenor/tfs"
)
type (
extent interface {
facade() pref.Facade
subscription() enums.Subscription
plugin(*kernel.Artefacts) enclave.Plugin
options([]Addon, ...pref.Option) (enclave.OptionHarvest, error)
forest() *core.Forest
complete() bool
}
)
type fileSystems struct {
fS tfs.TraversalFS
}
type baseExtent struct {
trees *core.Forest
fac pref.Facade
}
func (x *baseExtent) forest() *core.Forest {
return x.trees
}
func (x *baseExtent) facade() pref.Facade {
return x.fac
}
type primeExtent struct {
baseExtent
using *pref.Using
}
func (x *primeExtent) subscription() enums.Subscription {
return x.using.Subscription
}
func (x *primeExtent) plugin(*kernel.Artefacts) enclave.Plugin {
return nil
}
func (x *primeExtent) options(_ []Addon, settings ...pref.Option) (enclave.OptionHarvest, error) {
o, binder, err := opts.Get(settings...)
return &optionHarvest{
o: o,
binder: binder,
}, err
}
func (x *primeExtent) complete() bool {
return true
}
type resumeExtent struct {
baseExtent
relic *pref.Relic
loaded *opts.LoadInfo
pin *resume.Plugin
}
func (x *resumeExtent) subscription() enums.Subscription {
return x.loaded.State.Subscription
}
func (x *resumeExtent) plugin(artefacts *kernel.Artefacts) enclave.Plugin {
x.pin = resume.New(&resume.From{
Active: x.loaded.State,
Mediator: artefacts.Mediator,
Strategy: x.relic.Strategy,
IfResult: artefacts.IfResult,
})
return x.pin
}
func (x *resumeExtent) options(addons []Addon,
settings ...pref.Option,
) (enclave.OptionHarvest, error) {
loaded, binder, err := resume.Load(&enclave.RestoreState{
Path: x.relic.From,
FS: x.trees.R,
Strategy: x.relic.Strategy,
}, settings...)
x.loaded = loaded
if handler := x.seek(addons); handler != nil {
handler.OnLoad(loaded.State)
}
return &optionHarvest{
o: loaded.O,
binder: binder,
loaded: loaded,
}, err
}
func (x *resumeExtent) complete() bool {
return x.pin.IfResult.IsComplete()
}
func (x *resumeExtent) seek(addons []Addon) enclave.StateHandler {
if addon, found := lo.Find(addons, func(item Addon) bool {
_, ok := item.(enclave.StateHandler)
return ok
}); found {
result, _ := addon.(enclave.StateHandler)
return result
}
return nil
}