Skip to content

Commit

Permalink
Standardize server_variable_list() to variables()
Browse files Browse the repository at this point in the history
Closes #30.

This is the only place that variables() appears in the definition, and there's really no reason that it would have to be server-specific anyway.
  • Loading branch information
jonthegeek committed Sep 8, 2023
1 parent ce364a8 commit 3eb2c12
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export(info)
export(license)
export(rapid)
export(server_variable)
export(server_variable_list)
export(servers)
export(variables)
if (getRversion() < "4.3.0") importFrom("S7", "@")
importFrom(S7,class_any)
importFrom(S7,class_character)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#' @param ... One or more [server_variable()] objects, or a list of
#' [server_variable()] objects.
#'
#' @return A `server_variable_list` S7 object, which is a validated list of
#' @return A `variables` S7 object, which is a validated list of
#' [server_variable()] objects.
#' @export
#'
#' @examples
#' server_variable_list(
#' variables(
#' list(server_variable(), server_variable())
#' )
server_variable_list <- S7::new_class(
"server_variable_list",
variables <- S7::new_class(
"variables",
package = "rapid",
parent = class_list,
constructor = function(...) {
Expand Down
6 changes: 3 additions & 3 deletions R/servers-zz-servers.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param url A character vector of urls.
#' @param description A character vector of (usually brief) descriptions of
#' those urls.
#' @param variables A [server_variable_list()] object.
#' @param variables A [variables()] object.
#'
#' @return A `servers` S7 object, with properties `url`, `description`, and
#' `variables`.
Expand All @@ -29,7 +29,7 @@
#' servers(
#' url = "https://{username}.gigantic-server.com:{port}/{basePath}",
#' description = "The production API server",
#' variables = server_variable_list(server_variable(
#' variables = variables(server_variable(
#' name = c("username", "port", "basePath"),
#' default = c("demo", "8443", "v2"),
#' description = c(
Expand All @@ -49,7 +49,7 @@ servers <- S7::new_class(
properties = list(
url = class_character,
description = class_character,
variables = server_variable_list
variables = variables
),
validator = function(self) {
validate_parallel(
Expand Down
4 changes: 2 additions & 2 deletions man/servers.Rd

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

12 changes: 6 additions & 6 deletions man/server_variable_list.Rd → man/variables.Rd

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

Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
# server_variable_list() errors informatively for bad contents
# variables() errors informatively for bad contents

Code
server_variable_list(letters)
variables(letters)
Condition
Error:
! <rapid::server_variable_list> object is invalid:
! <rapid::variables> object is invalid:
- All values must be <server_variable> objects.
- Bad values at 1.

---

Code
server_variable_list(list(letters, letters))
variables(list(letters, letters))
Condition
Error:
! <rapid::server_variable_list> object is invalid:
! <rapid::variables> object is invalid:
- All values must be <server_variable> objects.
- Bad values at 1 and 2.

---

Code
server_variable_list(server_variable(), letters, server_variable(), letters)
variables(server_variable(), letters, server_variable(), letters)
Condition
Error:
! <rapid::server_variable_list> object is invalid:
! <rapid::variables> object is invalid:
- All values must be <server_variable> objects.
- Bad values at 2 and 4.

# server_variable_list() returns an empty server_variable_list
# variables() returns an empty variables

Code
server_variable_list()
variables()
Output
<rapid::server_variable_list> list()
<rapid::variables> list()

# server_variable_list() accepts bare server_variables
# variables() accepts bare server_variables

Code
server_variable_list(server_variable())
variables(server_variable())
Output
<rapid::server_variable_list> List of 1
<rapid::variables> List of 1
$ : <rapid::server_variable>
..@ name : chr(0)
..@ default : chr(0)
Expand All @@ -50,9 +50,9 @@
---

Code
server_variable_list(server_variable(), server_variable())
variables(server_variable(), server_variable())
Output
<rapid::server_variable_list> List of 2
<rapid::variables> List of 2
$ : <rapid::server_variable>
..@ name : chr(0)
..@ default : chr(0)
Expand All @@ -64,12 +64,12 @@
..@ enum : list()
..@ description: chr(0)

# server_variable_list() accepts lists of server_variables
# variables() accepts lists of server_variables

Code
server_variable_list(list(server_variable()))
variables(list(server_variable()))
Output
<rapid::server_variable_list> List of 1
<rapid::variables> List of 1
$ : <rapid::server_variable>
..@ name : chr(0)
..@ default : chr(0)
Expand All @@ -79,9 +79,9 @@
---

Code
server_variable_list(list(server_variable(), server_variable()))
variables(list(server_variable(), server_variable()))
Output
<rapid::server_variable_list> List of 2
<rapid::variables> List of 2
$ : <rapid::server_variable>
..@ name : chr(0)
..@ default : chr(0)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/servers-zz-servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<rapid::servers>
@ url : chr(0)
@ description: chr(0)
@ variables : <rapid::server_variable_list> list()
@ variables : <rapid::variables> list()

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/zz-rapid.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
@ servers: <rapid::servers>
.. @ url : chr(0)
.. @ description: chr(0)
.. @ variables : <rapid::server_variable_list> list()
.. @ variables : <rapid::variables> list()

35 changes: 0 additions & 35 deletions tests/testthat/test-servers-02-server_variable_list.R

This file was deleted.

35 changes: 35 additions & 0 deletions tests/testthat/test-servers-02-variables.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
test_that("variables() errors informatively for bad contents", {
expect_snapshot(
variables(letters),
error = TRUE
)
expect_snapshot(
variables(list(letters, letters)),
error = TRUE
)
expect_snapshot(
variables(
server_variable(),
letters,
server_variable(),
letters
),
error = TRUE
)
})

test_that("variables() returns an empty variables", {
expect_snapshot(variables())
})

test_that("variables() accepts bare server_variables", {
expect_snapshot(variables(server_variable()))
expect_snapshot(variables(server_variable(), server_variable()))
})

test_that("variables() accepts lists of server_variables", {
expect_snapshot(variables(list(server_variable())))
expect_snapshot(
variables(list(server_variable(), server_variable()))
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-servers-zz-servers.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("length() of a servers reports the overall length", {
servers(
url = "https://{username}.gigantic-server.com:{port}/{basePath}",
description = "The production API server",
variables = server_variable_list(server_variable(
variables = variables(server_variable(
name = c("username", "port", "basePath"),
default = c("demo", "8443", "v2"),
description = c(
Expand Down

0 comments on commit 3eb2c12

Please sign in to comment.