Skip to content

Commit

Permalink
Merge branch 'master' into f-#96-multi-row
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 6, 2016
2 parents 317280b + 9d8afd4 commit 0a31820
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Collate:
'import-dbi.R'
'import-testthat.R'
'run.R'
's4.R'
'spec.R'
'spec-getting-started.R'
'spec-driver-class.R'
Expand Down
49 changes: 49 additions & 0 deletions R/s4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# http://stackoverflow.com/a/39880324/946850
s4_methods <- function(env, pkg_fun = NULL) {
generics <- methods::getGenerics(env)

if (is.null(pkg_fun)) {
ok <- TRUE
} else {
ok <- pkg_fun(generics@package)
}


res <- Map(
generics@.Data[ok], generics@package[ok], USE.NAMES = TRUE,
f = function(name, package) {
what <- methods::methodsPackageMetaName("T", paste(name, package, sep = ":"))

table <- get(what, envir = env)

mget(ls(table, all.names = TRUE), envir = table)
})
unlist(res, recursive = FALSE)
}

s4_real_argument_names <- function(s4_method) {
expect_is(s4_method, c("function", "MethodDefinition", "derivedDefaultMethod"))
unwrapped <- s4_unwrap(s4_method)
names(formals(unwrapped))
}

s4_unwrap <- function(s4_method) {
# Only unwrap if body is of the following form:
# {
# .local <- function(x, y, z, ...) {
# ...
# }
# ...
# }
method_body <- body(s4_method)
if (inherits(method_body, "{")) {
local_def <- method_body[[2]]
if (inherits(local_def, "<-") && local_def[[2]] == quote(.local)) {
local_fun <- local_def[[3]]
if (inherits(local_fun, "function"))
return(local_fun)
}
}

s4_method
}
18 changes: 18 additions & 0 deletions R/spec-compliance-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ spec_compliance_methods <- list(
})
},

#' All methods have an ellipsis `...` in their formals.
ellipsis = function(ctx) {
pkg <- package_name(ctx)

where <- asNamespace(pkg)

methods <- s4_methods(where, function(x) x == "DBI")
Map(expect_ellipsis_in_formals, methods, names(methods))
},

#' }
NULL
)
Expand All @@ -41,6 +51,14 @@ expect_has_class_method <- function(name, class, args, driver_package) {
))
}

expect_ellipsis_in_formals <- function(method, name) {
sym <- as.name(name)
eval(bquote({
.(sym) <- method
expect_true("..." %in% s4_real_argument_names(.(sym)))
}))
}

key_methods <- list(
Driver = list(
"dbGetInfo" = NULL,
Expand Down

0 comments on commit 0a31820

Please sign in to comment.