source(file.path(usethis::proj_get(), "vignettes", "_common.R")) name <- "Order" domain <- "Pizza Ordering" commands <- "add_item_to_order" queries <- "review_order" path_proj <- tempfile("article-") path_script <- file.path("R", filename$entity(name, domain)) path_test <- file.path("tests", "testthat", "test-" %+% filename$entity(name, domain)) fs::dir_create(path_proj)
add_entity
do?Given the Entity name
, and its domain
name, and optionally commands
and queries
methods,
When add_entity
is called
command <- "add_entity(name = '" %+% name %+% "', domain = '" %+% domain %+% "', commands = '" %+% commands %+% "', queries = '" %+% queries %+% "')" withr::with_dir(path_proj, eval(parse(text=command)))
Then the function:
r path_script
;r path_test
;
andmessage("You don't need to remember the naming style for the different DDD components. Instead, <code>ddd</code> takes care of naming style for all domain objects. This way DDD file names, classes and functions are congruent with each other." )
The boilerplate code for the r name
Entity class produced by add_entity
looks like this:
r path_script
Notice the three public methods created by add_entity
:
initialize
is a constructor for new entities.
uid
) which
distinguishes it from other Entities.add_item_to_order
is a command boilerplate. You'll need to:
...
with explicit (if any) input arguments; andreview_order
is a query boilerplate. You'll need to:
The boilerplate code for the r name
Entity unit-test produced by add_entity
looks like this:
r path_test
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.