Skip to content

Commit

Permalink
Extract out check_pin_version helper
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Aug 6, 2021
1 parent fb6d53c commit cc72877
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
5 changes: 1 addition & 4 deletions R/board_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ pin_fetch.pins_board_folder <- function(board, name, version = NULL, ...) {
pin_meta.pins_board_folder <- function(board, name, version = NULL, ...) {
check_name(name)
check_pin_exists(board, name)

version <- version %||%
last(pin_versions(board, name)$version) %||%
abort("No versions found")
version <- check_pin_version(board, name, version)

path_version <- fs::path(board$path, name, version)
if (!fs::dir_exists(path_version)) {
Expand Down
9 changes: 1 addition & 8 deletions R/board_s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,7 @@ pin_version_delete.pins_board_s3 <- function(board, name, version, ...) {
#' @export
pin_meta.pins_board_s3 <- function(board, name, version = NULL, ...) {
check_pin_exists(board, name)

if (is.null(version)) {
version <- last(pin_versions(board, name)$version) %||% abort("No versions found")
} else if (is_string(version)) {
# check_pin_version(board, name, version)
} else {
abort("`version` must be a string or `NULL`")
}
version <- check_pin_version(board, name, version)

path_version <- fs::path(board$cache, name, version)
fs::dir_create(path_version)
Expand Down
11 changes: 11 additions & 0 deletions R/pin-meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ print.pins_meta <- function(x, ...) {
utils::str(unclass(x))
invisible(x)
}

check_pin_version <- function(board, name, version) {
if (is.null(version)) {
last(pin_versions(board, name)$version) %||% abort("No versions found")
} else if (is_string(version)) {
# TODO: provide pin_version_exists() so this can return informative error
version
} else {
abort("`version` must be a string or `NULL`")
}
}

0 comments on commit cc72877

Please sign in to comment.