Repository is archived
No commit activity in last 3 years
No release in over 3 years
Callback hooks for machinist blueprints
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 2.0.0
 Project Readme

machinist_callbacks¶ ↑

Some record construction rules cannot be expressed with a machinist blueprint, for instance:

  • Creating a record with a has_many association already filled in.

  • Creating a record with interdependencies between associated object, such as having to belong to the same container.

  • Needing to process a delayed_job queue after record construction.

This gem provides before_make and after_make callbacks for machinist blueprints, enabling more freedom in your construction rules.

Example¶ ↑

Movie.blueprint do
  title
  year 2001
  before_make do
    self.producer = Producer.make(:name => director.name)
  end
end
Director.blueprint do
  name
  after_make do
    movies << Movie.make
  end
end

Does it work with make_unsaved?¶ ↑

Yes. Machinist is built in a way that every make in your callback implicitely becomes a make_unsaved when an object graph is created with make_unsaved.

Installation¶ ↑

You can install the gem with

sudo gem install machinist_callbacks

In Rails 2, add the following to your environment.rb:

config.gem 'machinist_callbacks'

In Rails 3, add the following to your Gemfile:

gem 'machinist_callbacks'

Rails 3 compatibility¶ ↑

We cannot guarantee Rails 3 compatibility at this point, but we will upgrade the gem when Rails 3 is released.

Credits¶ ↑

Henning Koch

makandra.com

gem-session.com