Using Machinist, is there some way one can define blueprints such that they inherit attributes from other blueprints? I've looked at all the documentation and examples I've found, but I haven't seen it happening.
I want to do something like this:
User.blueprint do
name
email
end
User.blueprint(:admin) do
is_admin { true }
end
User.blueprint(:editor) do
is_editor { true }
group
end
User.blueprint(:contributor) do
is_editor { true }
end
Where they all inherit the name/email from the first blueprint, and the :contibutor blueprint inherits the group attribute from the :editor blueprint.
Is this possible?
Yes, that's partially possible, at least with Machinist 1 (I haven't tried with Machinist 2). You can only inherit attributes from the default blueprint of a given class.
Your syntax is correct, see "Named Blueprints" in https://github.com/notahat/machinist/tree/1.0-maintenance but your blueprint contributor directly inherits from the default User blueprint. You would have to set manually the group attribute in you contributor blueprint.
The syntax to create an admin user is User.make(:admin)
.