R/construct-s4.R

Defines functions construct.classRepresentation

#' @export
construct.classRepresentation <- function(data, defn, ...) {

  data %>%
    select(names(defn@slots)) %>%
    pmap(list) %>%
    map(~exec(new, defn, !!!.))

}

#' @export
deconstruct.classRepresentation <- function(objs, defn, ...) {

  map_dfr(
    objs,
    function(obj, slots) {
      map(slots, ~slot(obj, .)) %>%
        set_names(slots) %>%
        as_tibble_row()
    },
    slots = slotNames(defn)
  )

}

#' @export
construct.classGeneratorFunction <- function(data, defn, ...) {

  construct(data, getClass(defn@className), ...)

}

#' @export
deconstruct.classGeneratorFunction <- function(objs, defn, ...) {

  deconstruct(objs, getClass(defn@className), ...)

}
tjpalanca/dbtools documentation built on Oct. 7, 2021, 6:43 a.m.