• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / arche-serde / 12457234164

22 Dec 2024 07:57PM CUT coverage: 95.808% (+0.1%) from 95.679%
12457234164

Pull #15

github

web-flow
Merge 13e02ce48 into e0568ef0d
Pull Request #15: Get rid of the use of deprecated methods

17 of 17 new or added lines in 1 file covered. (100.0%)

320 of 334 relevant lines covered (95.81%)

39.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/options.go
1
package archeserde
2

3
import (
4
        "reflect"
5

6
        "github.com/mlange-42/arche/generic"
7
)
8

9
// Opts is a helper to create Option instances.
10
var Opts = Options{}
11

12
// Option is an option. Modifies o.
13
// Create them using [Opts].
14
type Option func(o *serdeOptions)
15

16
// Options is a helper to create Option instances.
17
// Use it via the instance [Opts].
18
type Options struct{}
19

20
// SkipAllResources skips serialization or de-serialization of all resources.
21
func (o Options) SkipAllResources() Option {
3✔
22
        return func(o *serdeOptions) {
6✔
23
                o.skipAllResources = true
3✔
24
        }
3✔
25
}
26

27
// SkipAllComponents skips serialization or de-serialization of all components.
28
func (o Options) SkipAllComponents() Option {
3✔
29
        return func(o *serdeOptions) {
6✔
30
                o.skipAllComponents = true
3✔
31
        }
3✔
32
}
33

34
// SkipEntities skips serialization or de-serialization of all entities and components.
35
func (o Options) SkipEntities() Option {
3✔
36
        return func(o *serdeOptions) {
6✔
37
                o.skipEntities = true
3✔
38
        }
3✔
39
}
40

41
// SkipAllResources skips serialization or de-serialization of certain components.
42
//
43
// When deserializing, the skipped components must still be registered.
44
func (o Options) SkipComponents(comps ...generic.Comp) Option {
3✔
45
        return func(o *serdeOptions) {
6✔
46
                o.skipComponents = make([]reflect.Type, len(comps))
3✔
47
                for i, c := range comps {
6✔
48
                        o.skipComponents[i] = reflect.Type(c)
3✔
49
                }
3✔
50
        }
51
}
52

53
// SkipAllResources skips serialization or de-serialization of certain resources.
54
//
55
// When deserializing, the skipped resources must still be registered.
56
func (o Options) SkipResources(comps ...generic.Comp) Option {
3✔
57
        return func(o *serdeOptions) {
6✔
58
                o.skipResources = make([]reflect.Type, len(comps))
3✔
59
                for i, c := range comps {
6✔
60
                        o.skipResources[i] = reflect.Type(c)
3✔
61
                }
3✔
62
        }
63
}
64

65
type serdeOptions struct {
66
        skipAllResources  bool
67
        skipAllComponents bool
68
        skipEntities      bool
69

70
        skipComponents []reflect.Type
71
        skipResources  []reflect.Type
72
}
73

74
func newSerdeOptions(opts ...Option) serdeOptions {
40✔
75
        o := serdeOptions{}
40✔
76
        for _, opt := range opts {
55✔
77
                opt(&o)
15✔
78
        }
15✔
79
        return o
40✔
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc