## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(fluffy)

## ----builtin rules------------------------------------------------------------
Registry()@rule_names

## ----rule categories----------------------------------------------------------
r <- Registry()
r@control_rules
r@transform_rules
r@validate_rules
r@finalize_rules

## ----schema rule function example, error=TRUE---------------------------------
try({
Schema(list(type = 1L), error = TRUE)
})

## ----validation rule function example, error=TRUE-----------------------------
try({
Validator(
  data = 1L,
  schema = list(type = "character"),
  error = TRUE
)
})

## ----cross rule example, error=TRUE-------------------------------------------
try({
Schema(
  list(
    min_length = 5,
    max_length = 1
  ),
  error = TRUE
)
})

## ----nchar rule example, eval=FALSE-------------------------------------------
# any(nchar(field) > schema_field, na.rm = TRUE)

## ----validation rules table, echo=FALSE, results='asis'-----------------------
x <- show_builtins("validation")
header <- stats::setNames(rep(1, length(x)), colnames(x))
new_colnames <- as.character(x[1, ])
base_table <- stats::setNames(x[-1, ], new_colnames)

kableExtra::add_header_above(
  knitr::kable(base_table, "html", row.names = FALSE),
  header
)

## ----cross rules table, echo=FALSE, results='asis'----------------------------
x <- show_builtins("cross")
header <- stats::setNames(rep(1, length(x)), colnames(x))
new_colnames <- as.character(x[1, ])
base_table <- stats::setNames(x[-1, ], new_colnames)

kableExtra::add_header_above(
  knitr::kable(base_table, "html", row.names = FALSE),
  header
)

