Skip to content

Commit

Permalink
create S3 methods for update_description()
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Aug 28, 2024
1 parent 6fa0835 commit 72f8e00
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ S3method(rm_data,character)
S3method(rm_data,default)
S3method(rm_data,git_repository)
S3method(summary,git2rdata)
S3method(update_description,character)
S3method(update_description,default)
S3method(update_description,git_repository)
S3method(upgrade_data,character)
S3method(upgrade_data,default)
S3method(upgrade_data,git_repository)
Expand Down
24 changes: 24 additions & 0 deletions R/update_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
#' @importFrom assertthat assert_that has_name
update_description <- function(
file, root = ".", field_description, name, title, description
) {
UseMethod("update_description", root)
}

#' @export
update_description.default <- function(
file, root = ".", field_description, name, title, description
) {
stop("a 'root' of class ", class(root), " is not supported", call. = FALSE)
}

#' @export
update_description.git_repository <- function(
file, root = ".", field_description, name, title, description
) {
update_description(
file = file, root = workdir(root), name = name, title = title,
description = description, field_description = field_description
)
}

#' @export
update_description.character <- function(
file, root = ".", field_description, name, title, description
) {
root <- normalizePath(root, winslash = "/", mustWork = TRUE)
file <- clean_data_path(root = root, file = file)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
test_that("description", {
expect_error(
update_description(
file = "test", root = data.frame()
),
"a 'root' of class data.frame is not supported"
)

root <- tempfile(pattern = "git2rdata-description")
dir.create(root)

Expand Down Expand Up @@ -35,6 +42,12 @@ test_that("description", {
expect_output(display_metadata(output, minimal = FALSE), "Table name: NA")
expect_output(display_metadata(output), "Table name: NA")

root <- git2r::init(root)
git2r::config(root, user.name = "Alice", user.email = "alice@example.org")
writeLines("ignore.*\nforce.*", file.path(git2r::workdir(root), ".gitignore"))
git2r::add(root, ".gitignore")
commit(root, "initial commit")

expect_null(
update_description(
file = "test", root = root, name = "my_table", title = "My Table",
Expand Down

0 comments on commit 72f8e00

Please sign in to comment.