-
Notifications
You must be signed in to change notification settings - Fork 11
/
value.go
50 lines (39 loc) · 1.08 KB
/
value.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
package the
import (
"qlova.org/seed/client"
"qlova.org/seed/client/clientside"
"qlova.org/seed/use/js"
)
//Value is a value.
type Value struct {
client.Value
components []client.Value
}
//Components implements clientside.Compound
func (a Value) Components() []client.Value {
return a.components
}
//ValueOf returns the Value of v.
func ValueOf(v client.Value, components ...client.Value) Value {
return Value{v, client.FlattenComponents(append(components, v)...)}
}
//Is returns a == b as a Value
func (a Value) Is(b client.Value) BoolExpression {
//Special optimised case.
if seca, ok := a.Value.(*clientside.Secret); ok {
if sb, ok := b.(client.String); ok {
return Bool(seca.Equals(sb), a, b)
}
}
return Bool(js.NewValue("(%v == %v)", a, b), a, b)
}
//IsNot returns a != b as a Value
func (a Value) IsNot(b client.Value) BoolExpression {
//Special optimised case.
if seca, ok := a.Value.(*clientside.Secret); ok {
if sb, ok := b.(client.String); ok {
return Bool(seca.Equals(sb).GetBool().Not(), a, b)
}
}
return Bool(js.NewValue("(%v != %v)", a, b), a, b)
}