Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update doc R6, fix docs check #530

Merged
merged 10 commits into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -77,4 +77,4 @@ Collate:
'session-cookie.R'
'swagger.R'
'utf8.R'
RoxygenNote: 6.1.1
RoxygenNote: 7.1.0
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -41,6 +41,8 @@ plumber 0.5.0

### Minor new features and improvements

* Update documentation on R6 objects (@meztez, #530)

* If cookie information is too large (> 4093 bytes), a warning will be displayed. ([#404](https://github.com/rstudio/plumber/pull/404))

* Added new shorthand types for url parameters. (@byzheng, [#388](https://github.com/rstudio/plumber/pull/388))
Expand Down
10 changes: 10 additions & 0 deletions R/plumber-static.R
Expand Up @@ -8,6 +8,10 @@ PlumberStatic <- R6Class(
"plumberstatic",
inherit = plumber,
public = list(
#' @description Create a new `plumberstatic` router
#' @param direc a path to an asset directory.
#' @param options options to be evaluated in the plumberstatic router environment
#' @return A new `plumberstatic` router
initialize = function(direc, options){
super$initialize(filters=NULL)

Expand Down Expand Up @@ -75,6 +79,12 @@ PlumberStatic <- R6Class(
filter <- PlumberFilter$new(paste("static-asset", direc, sep="|"), expr, private$envir)
private$addFilterInternal(filter)
},
#' @description Print reprensation of plumberstatic router.
meztez marked this conversation as resolved.
Show resolved Hide resolved
#' @param prefix a character string. Prefix to append to representation.
schloerke marked this conversation as resolved.
Show resolved Hide resolved
#' @param topLevel a logical value. When method executed on top level
#' router, set to `TRUE`.
#' @param ... additional arguments for recursive calls
#' @return A terminal friendly represention of a plumberstatic router.
meztez marked this conversation as resolved.
Show resolved Hide resolved
print = function(prefix="", topLevel=TRUE, ...){
cat(prefix)
if (!topLevel){
Expand Down
46 changes: 44 additions & 2 deletions R/plumber-step.R
Expand Up @@ -20,12 +20,23 @@ resetForward <- function() {
exec$forward <- FALSE
}

#' plumber step R6 class
#' @description an object representing a step in the lifecycle of the treatment
#' of a request by a plumber router.
PlumberStep <- R6Class(
"PlumberStep",
inherit=hookable,
public = list(
#' @field lines lines from step block
lines = NA,
#' @field serializer step serializer function
serializer = NULL,
#' @description Create a new `PlumberStep` object
meztez marked this conversation as resolved.
Show resolved Hide resolved
#' @param expr step expr
#' @param envir step environment
#' @param lines step block
#' @param serializer step serializer
#' @return A new `PlumberStep` object
initialize = function(expr, envir, lines, serializer){
private$expr <- expr
if (is.expression(expr)) {
Expand All @@ -44,6 +55,8 @@ PlumberStep <- R6Class(
self$serializer <- serializer
}
},
#' @description step execution function
#' @param ... additional arguments for step execution
exec = function(...) {
allArgs <- list(...)
args <- getRelevantArgs(allArgs, plumberExpression=private$func)
Expand Down Expand Up @@ -72,6 +85,9 @@ PlumberStep <- R6Class(
)
)
},
#' @description step hook registration method
#' @param stage a character string.
#' @param handler a step handler function.
registerHook = function(stage=c("preexec", "postexec"), handler){
stage <- match.arg(stage)
super$registerHook(stage, handler)
Expand Down Expand Up @@ -120,20 +136,44 @@ PlumberEndpoint <- R6Class(
"PlumberEndpoint",
inherit = PlumberStep,
public = list(
#' @field verbs a character vector. http methods. For historical reasons we have
#' to accept multiple verbs for a single path. Now it's simpler to just parse
#' each separate verb/path into its own endpoint, so we just do that.
verbs = NA,
#' @field path a character string. endpoint path
path = NA,
#' @field comments endpoint comments
comments = NA,
#' @field responses endpoint responses
responses = NA,
#' @description retrieve endpoint typed parameters
getTypedParams = function(){
data.frame(name=private$regex$names, type=private$regex$types, stringsAsFactors = FALSE)
},
#' @field params endpoint parameters
params = NA,
#' @field tags endpoint tags
tags = NA,
#' @description ability to serve request
#' @param req a request object
#' @return a logical. `TRUE` when endpoint can serve request.
canServe = function(req){
req$REQUEST_METHOD %in% self$verbs && !is.na(stringi::stri_match(req$PATH_INFO, regex=private$regex$regex)[1,1])
},
# For historical reasons we have to accept multiple verbs for a single path. Now it's simpler
# to just parse each separate verb/path into its own endpoint, so we just do that.
#' @description Create a new `PlumberEndpoint` object
#' @param verbs endpoint verb
#' @param path endpoint path
#' @param expr endpoint expr
#' @param envir endpoint environment
#' @param serializer endpoint serializer
#' @param lines endpoint block
#' @param params endpoint params
#' @param comments endpoint comments
#' @param responses endpoint responses
#' @param tags endpoint tags
#' @details Parameters values are obtained from parsing blocks of lines in a plumber file.
#' They can also be provided manually for historical reasons.
#' @return A new `PlumberEndpoint` object
initialize = function(verbs, path, expr, envir, serializer, lines, params, comments, responses, tags){
self$verbs <- verbs
self$path <- path
Expand Down Expand Up @@ -170,6 +210,8 @@ PlumberEndpoint <- R6Class(
self$tags <- I(tags)
}
},
#' @description retrieve endpoint path parameters
#' @param path endpoint path
getPathParams = function(path){
extractPathParams(private$regex, path)
}
Expand Down