-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add constraint support * Use custom constraint macro * Test multiple constraints * Avoid having to deal with macro name collisions * Avoid requiring Legolas in caller scope * Fix tests on Julia 1.6 * Update location comment * Add fail-safe comment * Set project version to 0.5.21 * Increase coverage * Add constraints into the tour * Add docstring for `@check`
- Loading branch information
Showing
7 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
struct CheckConstraintError <: Exception | ||
predicate::Expr | ||
end | ||
|
||
function Base.showerror(io::IO, ex::CheckConstraintError) | ||
print(io, "$CheckConstraintError: $(ex.predicate)") | ||
return nothing | ||
end | ||
|
||
""" | ||
@check expr | ||
Define a constraint for a schema version (e.g. `@check x > 0`) from a boolean expression. | ||
The `expr` should evaulate to `true` if the constraint is met or `false` if the constraint | ||
is violated. Multiple constraints may be defined for a schema version. All `@check` | ||
constraints defined with a [`@version`](@ref) must proceed all fields defined by the schema | ||
version. | ||
For more details and examples, please see `Legolas.jl/examples/tour.jl`. | ||
""" | ||
macro check(expr) | ||
quoted_expr = QuoteNode(expr) | ||
return :($(esc(expr)) || throw(CheckConstraintError($quoted_expr))) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7a50019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
7a50019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/114111
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: