= machinist_callbacks
Some record construction rules cannot be expressed with a {machinist}[http://github.com/notahat/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}[http://github.com/tobi/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 and setup
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
{gem-session.com}[http://gem-session.com/]
{www.makandra.de}[http://www.makandra.de/]