library(crudr) run <- FALSE root_dir <- paste(rep("../", 1), collapse = "") knitr::opts_chunk$set(comment = "#>", collapse = TRUE) knitr::opts_knit$set(root.dir = root_dir)
crudr_uml <- ' @startuml ICrud *-- Crud: implements < Crud <|-- Crud.Settings: extends < class ICrud { +init() +has() +create() +read() +update() +delete() +reset() -stopIfInterface() } class Crud { +main: environment -initial_state: list -stopIfEmpty() -createMessage(), -cacheInitialState() } class Crud.Settings { +main: function -cacheInitialState() } @enduml ' # knitr::opts_knit$set(root.dir = root_dir) uml_file <- crudr:::plantuml3( crudr_uml, 'Architecture', filename = "vignettes/uml", jarfile = "lib/plantuml.jar", normalize = TRUE ) # print(uml_file) # uml_file <- normalizePath(uml_file) # print(uml_file) # print(getwd()) # knitr::opts_knit$set(root.dir = getwd())
Class ICrud
serves as the inferface class that can be implemented by other classes. It defines nothing but the publicly available methods.
As no explicit instances of this class should be created/used, calling the its methods results in an error informing the user that he is working with the interface itself instead of an implementation of the interface.
inst <- ICrud$new() try(inst$init()) try(inst$has()) try(inst$create()) try(inst$read()) try(inst$update()) try(inst$delete()) try(inst$reset())
Class Crud
implements the interface ICrud
and serves as a base clase for inheritance.
inst <- Crud$new() class(inst) inherits(inst, "ICrud")
inst <- Crud$new(main = as.environment(list(a = 1, b = 2))) value <- inst$getMain() as.list(value, sorted = TRUE) inst$setMain(as.environment(list(a = 10, b = 20))) inst$getMain()$a inst$getMain()$b
inst <- Crud$new()
Provide initial values.
Note the flexible format by which you can provide input.
inst$init(a = 1, b = 2, "c/foo/bar" = 3, list(d = 4, "e/foo/bar" = 5))
Check if values exist based on one or multiple keys:
inst$has("a") inst$has("c/foo") inst$has("a", "b") inst$has("a", "e/foo/bar") inst$has("c") inst$has("a", "c", "c/bar")
Create one or multiple key-value pairs. Takes into consideration existing key-value pairs which, by default, are not overwritten. Overwrites need to be explicitly authorized by overwrite = TRUE
.
Note the different levels of strictness that can be applied. This is something that most methods support.
inst$create(f = TRUE) inst$create(g = TRUE, h = letters[1:3]) inst$create("i/foo" = 1, "c/foo/bar/new" = 1) ## TODO 2015-11-04: review behavior for preserving values; turning everything ## into a list would probably be nicer as would happen when calling ## `inst$create("i/foo" = 1, "c/foo/bar/new/something" = 1)` as.list(inst$getMain(), sorted = TRUE) (inst$create(c = 30, "c/foo" = 30)) ## --> c already existed with value = 3 as.list(inst$getMain(), sorted = TRUE) inst$create(c = 30, strict = 1) try(inst$create(c = 30, strict = 2)) try(inst$create(c = 30, strict = 3)) ## Overwrite // inst$create(c = 30, "c/foo" = 30, overwrite = TRUE) ## TODO 2015-11-04: review behavior for preserving values; turning everything ## into a list would probably be nicer as.list(inst$getMain(), sorted = TRUE) ## --> c overwritten
Read/get values by one or multiple keys. Non-existing key-value pairs will result in return values of NULL.
Strictness levels 0
through 3
apply.
inst$read() inst$read("a") inst$read("a", "b", "c/foo") inst$read("a", "b", "x") try(inst$read("a", "b", "x", strict = 3))
Update values by one or multiple keys.
Strictness levels 0
through 3
apply.
inst$read("a") inst$update(a = 10) inst$read("a") inst$read("a", "b") inst$update(a = 1000, b = 2000) inst$read("a", "b") inst$update(x = 99) inst$read("x") inst$read("a", "x") inst$update(a = 1, x = 99) try(inst$update(a = 1, x = 99, strict = 3)) inst$read("a", "x")
Delete key-value pairs based on keys. Only existing pairs can be deleted.
Strictness levels 0
through 3
apply.
inst$read() inst$delete("f") inst$delete("d", "c") inst$read() inst$delete("x") inst$read() inst$delete("b", "x") try(inst$delete("b", "x", strict = 3)) inst$read()
inst$reset() inst$read() inst$reset(type = "hard") inst$read()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.