You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Overview
Extends rules so that they can be used to against dbt
[sources](https://docs.getdbt.com/docs/build/sources) in addition to
models.
# Usage
A rule defines what resource-type it acts against in the type signature
of the function it wraps or in a class-based `evaluate` method:
```python
from dbt_score import Model, Source rule, Rule, RuleViolation
# decorator-based
# for a Model
@rule
def model_has_description(model: Model) -> RuleViolation | None:
"""A model should have a description."""
if not model.description:
return RuleViolation(message="Model lacks a description.")
# for a Source
@rule
def has_description(source: Source) -> RuleViolation | None:
"""A source should have a loader defined."""
if not source.loader:
return RuleViolation(message="Source lacks a loader.")
# class-based
class ExampleSource(Rule):
"""Example class-based rule."""
description = "A source should have a loader defined."
def evaluate(self, source: Source) -> RuleViolation | None:
"""Evaluate source."""
if not source.loader:
return RuleViolation(message="Source lacks a loader.")
```
The `Evaluation` handler is then responsible for applying source-rules
to Source objects and model-rules to Model objects.
---
closes#76
---------
Co-authored-by: Jochem van Dooren <[email protected]>
Co-authored-by: Jochem van Dooren <[email protected]>
Co-authored-by: Matthieu Caneill <[email protected]>
0 commit comments