O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required