Meta
Meta inspectors apply other inspection functions.
meta.condition
Evaluates data with a condition (operator, inspectors) applied as an inspector. This inspector makes it possible to create complex conditions that are otherwise impossible, such as:
- ( foo OR bar ) AND ( baz OR qux )
- ( foo AND bar ) OR ( baz AND qux )
Settings
Field | Type | Description | Required |
---|---|---|---|
condition | object | The condition used during inspection. | Yes |
Example
sub.condition.meta.condition(
settings={condition: sub.condition.all([
sub.condition.format.json(),
sub.condition.number.length.greater_than(settings={value: 100})
])}
)
sub.cnd.meta.cnd({condition: sub.cnd.all([
sub.cnd.fmt.json(),
sub.cnd.num.len.gt({value: 100})
])})
meta.for_each
Evaluates elements in an array and applies an inspector to each value.
Settings
Field | Type | Description | Required |
---|---|---|---|
object.source_key | string | Retrieves an array value from an object for inspection. | No |
inspector | object | The inspector applied to each element in the array. | Yes |
type | string | Determines the method of combining results from the inspector. Must be one of: - none: None of the elements from the array match the inspector. - any: At least one of the elements from the array match the inspector. - all: All of the elements form the array match in the inspector. | Yes |
Example
sub.condition.meta.for_each(
settings={type: 'any', inspector: sub.condition.string.greater_than(settings={value: '0'})}
)
sub.cnd.meta.for_each({type: 'any', inspector: sub.cnd.str.gt({value: '0'})})
meta.negate
Evaluates data with an inspector that is negated (true becomes false, false becomes true).
Settings
Field | Type | Description | Required |
---|---|---|---|
inspector | object | The inspector that is negated. | Yes |
Example
sub.condition.meta.negate(
settings={inspector: sub.condition.string.greater_than(settings={value: '0'})}
)
sub.cnd.meta.negate({inspector: sub.cnd.str.gt(settings={value: '0'})})
Use Cases
NOT Matching
The meta_negate
inspector is required to implement NOT logic such as:
- string matches /^[Aa]/ AND NOT length(value) >= 10
Chaining OR / AND
The logic ( foo AND bar ) OR ( baz AND qux )
is possible by using the meta_condition
inspector and combining an any
-based condition with all
-based conditions as inspectors. In this example, the value of foo
is copied to bar
if either of these conditions is true:
- the value of
foo
has a length greater than zero and starts with the substring "x" - the value of
foo
has a length less than four and ends with the substring "ar"
Chaining AND / OR
The logic ( foo OR bar ) AND ( baz OR qux )
is possible by using the meta_condition
inspector and combining an all
-based condition with any
-based conditions as inspectors. In this example, the value of foo
is copied to bar
if both of these conditions is true:
- the value of
foo
starts with the substring "b" or starts with the substring "x" - the value of
foo
has a length greater than two or a length less than five
Updated 10 months ago