Sha256: 2742303bcee681c4cfc60f85674d6b61c2431412620d9a37036ff0fe69d49319

Contents?: true

Size: 704 Bytes

Versions: 6

Compression:

Stored size: 704 Bytes

Contents

---
layout: default
title: Lifecycle Hooks
parent: Usage
nav_order: 8
---

# Lifecycle Hooks

Faker Maker has a few hooks which can be added to the factory which are triggered when the factory builds an instance.

* `before_build` the instance has been created but none of the values have been set yet
* `after_build` the instance has been created and all of the values have been set

For instance:

```ruby
FakerMaker.factory :user do 
  before_build do |instance, factory|
    puts 'Building an instance of User'
  end

  name {'Patsy Stone'}
  email {'patsy@fabulous.co.uk'}
  admin {false}
  
  after_build do |instance, factory|
    puts "Built an instance of User (#{instance.name})"
  end
end
```

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
faker_maker-2.1.2 docs/usage/lifecycle_hooks.md
faker_maker-2.1.1 docs/usage/lifecycle_hooks.md
faker_maker-2.0.0 docs/usage/lifecycle_hooks.md
faker_maker-1.3.0 docs/usage/lifecycle_hooks.md
faker_maker-1.2.1 docs/usage/lifecycle_hooks.md
faker_maker-1.2.0 docs/usage/lifecycle_hooks.md