comparison BiodbObject.R @ 2:20d69a062da3 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
author prog
date Thu, 02 Mar 2017 08:55:00 -0500
parents
children
comparison
equal deleted inserted replaced
1:253d531a0193 2:20d69a062da3
1 ##########################
2 # CLASS DECLARATION {{{1 #
3 ##########################
4
5 BiodbObject <- methods::setRefClass("BiodbObject", fields = list( .observers = "ANY" ))
6
7 ########################
8 # ABSTRACT METHOD {{{1 #
9 ########################
10
11 BiodbObject$methods( .abstract.method = function() {
12
13 class <- class(.self)
14 method <- sys.call(length(sys.calls()) - 1)
15 method <- sub('^[^$]*\\$([^(]*)\\(.*$', '\\1()', method)
16
17 stop(paste("Method", method, "is not implemented in", class, "class."))
18 })
19
20 ######################
21 # ADD OBSERVERS {{{1 #
22 ######################
23
24 BiodbObject$methods( addObservers = function(obs) {
25
26 # Check types of observers
27 if ( ( ! is.list(obs) && ! inherits(obs, "BiodbObserver")) || (is.list(obs) && any( ! vapply(obs, function(o) inherits(o, "BiodbObserver"), FUN.VALUE = TRUE))))
28 stop("Observers must inherit from BiodbObserver class.")
29
30 # Add observers to current list
31 .observers <<- if (is.null(.self$.observers)) c(obs) else c(.self$.observers, obs)
32 })