Skip to contents

Generate the check function for an action, and use it to create a scene_action object.

Usage

construct_action(fn, ..., negate = FALSE, methods = "GET")

Arguments

fn

A function that takes a request (and potentially other arguments) and returns TRUE or FALSE.

...

Additional parameters passed on to fn.

negate

If TRUE, trigger the corresponding scene when this action is not matched.

methods

The http methods which needs to be accepted in order for this function to make sense. Default "GET" should work in almost all cases.

Value

A scene_action.

Examples

simple_function <- function(request) {
  !missing(request) && length(request) > 0
}
sample_action <- construct_action(simple_function)
sample_action$check_fn()
#> [1] FALSE
sample_action$check_fn(list())
#> [1] FALSE
sample_action$check_fn(list(a = 1))
#> [1] TRUE