Skip to content

Commit

Permalink
Add pin name to metadata
Browse files Browse the repository at this point in the history
Fixes #544
  • Loading branch information
hadley committed Dec 13, 2021
1 parent 3798d89 commit 10303c6
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pins (development version)

* `pin_meta()` now includes pin `name` (#544).

* `board_deparse()` is more likely to generate runnable code when used
with `board_rsconnect()` (#553).

Expand Down
1 change: 1 addition & 0 deletions R/board_azure.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pin_meta.pins_board_azure <- function(board, name, version = NULL, ...) {
azure_download(board, metadata_blob, progress = FALSE)
local_meta(
read_meta(fs::path(board$cache, name, version)),
name = name,
dir = path_version,
version = version
)
Expand Down
2 changes: 1 addition & 1 deletion R/board_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pin_meta.pins_board_folder <- function(board, name, version = NULL, ...) {
}

meta <- read_meta(path_version)
local_meta(meta, dir = path_version, version = version)
local_meta(meta, name = name, dir = path_version, version = version)
}

#' @export
Expand Down
2 changes: 2 additions & 0 deletions R/board_kaggle.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pin_meta.pins_board_kaggle_competition <- function(board, name, ...) {
api_version = 1
)
local_meta(meta,
name = name,
version = NA_character_,
dir = fs::path(board$cache, name),
url = competition$url
Expand Down Expand Up @@ -289,6 +290,7 @@ pin_meta.pins_board_kaggle_dataset <- function(board, name, version = NULL, ...)
api_version = 1
)
local_meta(meta,
name = name,
version = view$currentVersionNumber,
dir = fs::path(board$cache, name),
url = view$url
Expand Down
1 change: 1 addition & 0 deletions R/board_ms365.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pin_meta.pins_board_ms365 <- function(board, name, version = NULL, ...) {
ms365_download(board, metadata_key)
local_meta(
read_meta(fs::path(board$cache, name, version)),
name = name,
dir = path_version,
version = version
)
Expand Down
1 change: 1 addition & 0 deletions R/board_rsconnect.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pin_meta.pins_board_rsconnect <- function(board, name, version = NULL, ...) {

meta <- read_meta(cache_path)
local_meta(meta,
name = name,
dir = cache_path,
url = url,
version = bundle_id,
Expand Down
1 change: 1 addition & 0 deletions R/board_s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pin_meta.pins_board_s3 <- function(board, name, version = NULL, ...) {
s3_download(board, metadata_key, immutable = TRUE)
local_meta(
read_meta(fs::path(board$cache, name, version)),
name = name,
dir = path_version,
version = version
)
Expand Down
2 changes: 2 additions & 0 deletions R/board_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pin_meta.pins_board_url <- function(board, name, version = NULL, ...) {
)
meta <- read_meta(cache_dir)
local_meta(meta,
name = name,
dir = cache_dir,
url = url,
file_url = paste0(url, meta$file)
Expand All @@ -102,6 +103,7 @@ pin_meta.pins_board_url <- function(board, name, version = NULL, ...) {
api_version = 1
)
local_meta(meta,
name = name,
dir = cache_dir,
url = url,
file_url = url
Expand Down
5 changes: 4 additions & 1 deletion R/pin-meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' Pin metadata comes from three sources:
#'
#' * Standard metadata added by `pin_upload()`/`pin_write()`. This includes:
#' * `$name` - the pin's name.
#' * `$file` - names of files stored in the pin.
#' * `$file_size` - size of each file.
#' * `$pin_hash` - hash of pin contents.
Expand Down Expand Up @@ -71,7 +72,8 @@ multi_meta <- function(board, names) {
#' @noRd
#' @param dir Path to local cache directory
#' @param url Remote url to pin; used `pin_browser()`
local_meta <- function(x, dir, url = NULL, version = NULL, ...) {
local_meta <- function(x, name, dir, url = NULL, version = NULL, ...) {
x$name <- name
x$local <- list(
dir = dir,
url = url,
Expand All @@ -85,6 +87,7 @@ test_api_meta <- function(board) {
testthat::test_that("can round-trip pin metadata", {
name <- local_pin(board, 1, title = "title", description = "desc", metadata = list(a = "a"))
meta <- pin_meta(board, name)
testthat::expect_equal(meta$name, name)
testthat::expect_equal(meta$title, "title")
testthat::expect_equal(meta$description, "desc")
testthat::expect_equal(meta$user$a, "a")
Expand Down

0 comments on commit 10303c6

Please sign in to comment.