Read more

Machinist: Refer to another named blueprint inside a blueprint

Arne Hartherz
October 06, 2010Software engineer at makandra GmbH

Note: We are talking about Machinist 1 Show archive.org snapshot here, Machinist 2 may have solved this or might require a different approach.


Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Machinist allows named blueprints (e.g. User.blueprint(:admin)) that inherit from the master blueprint (User.blueprint).

If you also want to inherit from another blueprint (e.g. if "vip" should load "premium" and the master blueprint) you can do this:
User.blueprint(:vip) do
# Fields for the vip blueprint go here
instance_eval(&User.blueprint(:premium))
end

To do pretty things like...

User.blueprint(:vip) do
  # Fields for the vip blueprint go here
  inherit :premium
end

...put the attached code into spec/support/machinist_inherit.rb and require 'spec/support/machinist_inherit' in your blueprints.rb. Note that it might not be sufficient to put the file into spec/support and have the spec_helper.rb require everything in that folder. Your blueprints.rb might be required before machinist_inherit.rb.

Note: Attributes that are already set will not be overwritten when defined again. Thus, put your inherit calls after all other attribute definitions inside a blueprint.

Posted by Arne Hartherz to makandra dev (2010-10-06 17:09)