Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Conditioner is an extension that can check conditions of the previous results to determine if the relationship should continue. It gives you the ability to have an unlimited number of nested ANDs + ORs to make complete conditions

Conditions are added to the relationships table under the conditions column and are formatted in json.

Nested values are translated to dot patterns


Matchers

Code Block
languageruby
equal?(fact, value, values)     # are the two values equal including class
not_equal?(fact, value, values) # are the two values no equal
nil?(fact, values)              # checks if the value doesn't exist
not_nil?(fact, values)          # checks if the value exists
is_false?(fact, values)         # checks if the value is false
is_true?(fact, values)          # checks if the value if true
is_array?(fact, values)         # checks if the value is an array
is_string?(fact, values)        # checks if the value is a string
is_integer(fact, values)        # checks if the value is a number

The operator when creating conditions is equal to the method name without the ? so equal? becomes equal, is_true? becomes is_true

Examples

Expand
titlepet is a dog and is hungry

In the first example, the pet type must be dog and the pet must be hungry

Code Block
languagejson
{
  "all": [{
    "fact": "pet.type",
	"value": "dog",
	"operator": "equal"
  },{
	"fact":"pet.hungry",
	"operator":"is_true"
  }]
}

All of these scenarios would fail the conditioner

Code Block
{ "pet": { "type":"cat", "hungry":true } }
{ "pet": { "type":"dog", "hungry":false } }
{ "pet": { "type":"dog", "hungry":"true" } }
{ "person": { "hungry":true } }

This scenario would pass

Code Block
{ "pet": { "type": "dog", "hungry": true } }

Expand
titlemust be a dog or a cat

In the second scenario, the pet must be a dog or a cat using an OR condition

Code Block
languagejson
{
  "any": [{
	"fact": "pet.type",
	"value": "dog",
	"operator": "equal"
  },{
	"fact":"pet.type",
	"value":"cat",
	"operator":"equal"
  }]
}

Example payloads

Code Block
languagejson
{ "pet": { "type": "dog" } }                    # would fail
{ "pet": { "type": "dog", "is_hungry": true } } # would fail
{ "pet": { "type": "cat", "sex": "male" } }     # would fail 
{ "pet": { "type": "turtle" }                   # would pass

Expand
titleNesting ands and ors

The last scenario is a combination of ands and ors

Code Block
{
  "all": [
	"any":[
	  {"fact":"pet.type", "value":"dog","operator":"equal"},
	  {"fact":"pet.type", "value":"cat","operator":"equal"}
	]
	{
	  "fact": "pet.hungry",
	  "operator": "is_true"
	},{
	  "fact":"pet.overweight",
	  "operator":"is_false"
	}]
}

Example Payloads

Code Block
languagejson
{"pet":{"type":"dog", "hungry":true, "overweight":true}}     # would fail
{"pet":{"type":"dog", "hungry":false, "overweight":true}}    # would fail
{"pet":{"type":"dog", "hungry":false, "overweight":false}}   # would fail
{"pet":{"type":"turtle", "hungry":true, "overweight":false}} # would fail
{"pet":{"type":"cat", "hungry":true, "overweight":true}}     # would fail

{"pet":{"type":"dog", "hungry":true, "overweight":false}}    # would pass
{"pet":{"type":"cat", "hungry":true, "overweight":false}}    # would pass