1
0
mirror of synced 2026-01-02 03:02:26 -05:00
Files
airbyte/airbyte-cdk/python/airbyte_cdk/sources/declarative/interpolation/interpolated_boolean.py
Brian Lai ccbd7c6508 conditional paginator + interpolated boolean components (#13389)
* conditional paginator + interpolated boolean components

* fix bug where empty arrays and dicts evaluated to true

* add more falsey values

* adjust falsey values and tweak based on review comments
2022-06-01 20:24:32 -04:00

25 lines
837 B
Python

#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
from airbyte_cdk.sources.declarative.interpolation.jinja import JinjaInterpolation
false_values = {"False", "false", "{}", "[]", "()", "", "0", "0.0", "False", "false"}
class InterpolatedBoolean:
def __init__(self, condition):
self._condition = condition
self._default = "False"
self._interpolation = JinjaInterpolation()
def eval(self, config, **kwargs):
if isinstance(self._condition, bool):
return self._condition
else:
evaluated = self._interpolation.eval(self._condition, config, self._default, **kwargs)
if evaluated in false_values:
return False
# The presence of a value is generally regarded as truthy, so we treat it as such
return True