Skip to content

Commit

Permalink
Make pkg_agent() play nice. (#27)
Browse files Browse the repository at this point in the history
Closes #26.
  • Loading branch information
jonthegeek committed Sep 15, 2023
1 parent 0623e72 commit ac70c2e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(generate_pkg)
export(pkg_agent)
export(generate_pkg_agent)
export(use_beekeeper)
if (getRversion() < "4.3.0") importFrom("S7", "@")
importFrom(glue,glue)
Expand Down
26 changes: 1 addition & 25 deletions R/generate.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @return `TRUE` invisibly.
#' @export
generate_pkg <- function(config_file = "_beekeeper.yml",
pkg_agent = pkg_agent(fs::path_dir(config_file))) {
pkg_agent = generate_pkg_agent(config_file)) {
.assert_is_pkg()
config <- .read_config(config_file)
api_definition <- readRDS(
Expand Down Expand Up @@ -107,27 +107,3 @@ generate_pkg <- function(config_file = "_beekeeper.yml",

return(invisible(target))
}

#' Create a user agent for the active package
#'
#' @param path The path to the DESCRIPTION file, or to a directory within a
#' package.
#'
#' @return A string with the name of the package and (if available) the first
#' URL associated with the package.
#'
#' @export
pkg_agent <- function(path = ".") {
pkg_desc <- desc::desc(file = path)
pkg_name <- pkg_desc$get_field("Package")
pkg_url_glue <- ""
pkg_url <- pkg_desc$get_urls()
if (length(pkg_url)) {
pkg_url_glue <- glue::glue(
" ({pkg_url[[1]]})"
)
}
return(
glue::glue("{pkg_name}{pkg_url_glue}")
)
}
26 changes: 26 additions & 0 deletions R/generate_pkg_agent.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Create a user agent for the active package
#'
#' @param path The path to the DESCRIPTION file, or to a directory within a
#' package.
#'
#' @return A string with the name of the package and (if available) the first
#' URL associated with the package.
#'
#' @export
generate_pkg_agent <- function(path = ".") {
if (!fs::is_dir(path) && fs::path_file(path) != "DESCRIPTION") {
path <- fs::path_dir(path) # nocov
}
pkg_desc <- desc::desc(file = path)
pkg_name <- pkg_desc$get_field("Package")
pkg_url_glue <- ""
pkg_url <- pkg_desc$get_urls()
if (length(pkg_url)) {
pkg_url_glue <- glue::glue(
" ({pkg_url[[1]]})"
)
}
return(
glue::glue("{pkg_name}{pkg_url_glue}")
)
}
2 changes: 1 addition & 1 deletion man/generate_pkg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/pkg_agent.Rd → man/generate_pkg_agent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions tests/testthat/test-generate.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,3 @@ test_that("Applying a 1-server config generates the expected R files.", {
"nectar"
)
})

test_that("pkg_agent() generates package agents", {
expect_identical(
pkg_agent(test_path("_fixtures", "DESCRIPTION")),
"beekeeper (https://jonthegeek.github.io/beekeeper/)"
)
})
6 changes: 6 additions & 0 deletions tests/testthat/test-generate_pkg_agent.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("generate_pkg_agent() generates package agents", {
expect_identical(
generate_pkg_agent(test_path("_fixtures", "DESCRIPTION")),
"beekeeper (https://jonthegeek.github.io/beekeeper/)"
)
})

0 comments on commit ac70c2e

Please sign in to comment.