-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added utility to unpack a Gobbler path to its project/asset/version d…
…etails.
- Loading branch information
Showing
5 changed files
with
71 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#' Unpack a path to its project-asset-version combination | ||
#' | ||
#' Unpack a Gobbler path to its combination of project, asset, version, and (optionally) path, | ||
#' for easier use in the various \pkg{gobbler} functions. | ||
#' | ||
#' @param path String containing a relative path within the Gobbler registry. | ||
#' | ||
#' @return List containing \code{project}, \code{asset}, \code{version} and \code{path}. | ||
#' All are strings, except for \code{path}, which may be \code{NULL}. | ||
#' | ||
#' @author Aaron Lun | ||
#' | ||
#' @examples | ||
#' unpackPath("project/asset/version/path") | ||
#' unpackPath("project/asset/version") | ||
#' | ||
#' @export | ||
#' @importFrom utils tail | ||
unpackPath <- function(path) { | ||
components <- strsplit(path, "/")[[1]] | ||
stopifnot(length(components) >= 3L) | ||
if (length(components) == 3L || components[4] == "") { | ||
path <- NULL | ||
} else { | ||
path <- paste(tail(components, -3), collapse="/") | ||
} | ||
list(project=components[1], asset=components[2], version=components[3], path=path) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
# library(gobbler); library(testthat); source("test-unpackPath.R") | ||
|
||
test_that("unpackPath works as expected", { | ||
out <- unpackPath("project/asset/version/path") | ||
expect_identical(out, list(project="project", asset="asset", version="version", path="path")) | ||
|
||
out <- unpackPath("project/asset/version") | ||
expect_identical(out, list(project="project", asset="asset", version="version", path=NULL)) | ||
|
||
out <- unpackPath("project/asset/version/") | ||
expect_identical(out, list(project="project", asset="asset", version="version", path=NULL)) | ||
}) |