Skip to content

Commit

Permalink
Evalauate all file expression blocks only once, not once or twice
Browse files Browse the repository at this point in the history
Fixes tests made in #331
  • Loading branch information
schloerke committed Nov 5, 2018
1 parent fb41fa1 commit cde0d3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 6 additions & 0 deletions R/parse-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ activateBlock <- function(srcref, file, expr, envir, addEndpoint, addFilter, mou
stopOnLine(lineNum, file[lineNum], "A single function can only be a filter, an API endpoint, or an asset (@filter AND @get, @post, @assets, etc.)")
}

# ALL if statements possibilities must eventually call eval(expr, envir)
if (!is.null(block$paths)){
lapply(block$paths, function(p){
ep <- PlumberEndpoint$new(p$verb, p$path, expr, envir, block$serializer, srcref, block$params, block$comments, block$responses, block$tags)
Expand All @@ -253,6 +254,7 @@ activateBlock <- function(srcref, file, expr, envir, addEndpoint, addFilter, mou
} else if (!is.null(block$filter)){
filter <- PlumberFilter$new(block$filter, expr, envir, block$serializer, srcref)
addFilter(filter)

} else if (!is.null(block$assets)){
path <- block$assets$path

Expand All @@ -263,5 +265,9 @@ activateBlock <- function(srcref, file, expr, envir, addEndpoint, addFilter, mou

stat <- PlumberStatic$new(block$assets$dir, expr)
mount(path, stat)

} else {

eval(expr, envir)
}
}
3 changes: 0 additions & 3 deletions R/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ plumber <- R6Class(
if (!is.null(file)){
private$lines <- readUTF8(file)
private$parsed <- parseUTF8(file)
# populate the local envir with parameters defined within the file
# https://github.com/trestletech/plumber/issues/329
sourceUTF8(file, private$envir)

for (i in 1:length(private$parsed)){
e <- private$parsed[i]
Expand Down

0 comments on commit cde0d3d

Please sign in to comment.