File: spec-driver-constructor.R

package info (click to toggle)
r-cran-dbitest 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,216 kB
  • sloc: sh: 10; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#' spec_driver_constructor
#' @family driver specifications
#' @usage NULL
#' @format NULL
#' @keywords NULL
#' @section Construction of the DBIDriver object:
spec_driver_constructor <- list(
  constructor = function(ctx) {
    pkg_name <- package_name(ctx)

    #' The backend must support creation of an instance of its [DBIDriver-class] subclass
    #' with a \dfn{constructor function}.
    #' By default, its name is the package name without the leading \sQuote{R}
    #' (if it exists), e.g., `SQLite` for the \pkg{RSQLite} package.
    default_constructor_name <- gsub("^R", "", pkg_name)

    #' However, backend authors may choose a different name.
    constructor_name <- ctx$tweaks$constructor_name %||% default_constructor_name

    #' The constructor must be exported, and
    pkg_env <- getNamespace(pkg_name)
    eval(bquote(
      expect_true(.(constructor_name) %in% getNamespaceExports(pkg_env))
    ))

    #' it must be a function
    eval(bquote(
      expect_true(exists(.(constructor_name), mode = "function", pkg_env))
    ))
    constructor <- get(constructor_name, mode = "function", pkg_env)

    #' that is callable without arguments.
    expect_all_args_have_default_values(constructor)
    #' DBI recommends to define a constructor with an empty argument list.
    if (!isTRUE(ctx$tweaks$constructor_relax_args)) {
      expect_arglist_is_empty(constructor)
    }
  },
  #
  NULL
)