Registering Templates and Prototypes with Forge

You’ll register each data template in a module usually called Forge. This is a template for a Person. Notice the Faker framework that we use to fake individual elements:

 ~~~
 defmodule Forge do
  use Blacksmith
  register :user,
  first_name: Faker.Name.first_name,
  last_name: Faker.Name.last_name,
  email: Sequence.next(:email, &"test#{&1}@example.com")
 
 
  register :admin,
  [prototype: user],
  roles: ["admin"]
 end
 ~~~

We’re registering each type of entity in our Forge module. The first entry registers users. The Faker library supplies plausible values for first_name and last_name. We use a sequence to create an email so that each email for a new user will be unique. Blacksmith registers ...

Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.