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.
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
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.
You can install the gem with
sudo gem install machinist_callbacks
In Rails 2, add the following to your environment.rb:
In Rails 3, add the following to your Gemfile:
We cannot guarantee Rails 3 compatibility at this point, but we will upgrade the gem when Rails 3 is released.