Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterized blueprints #45

Closed
pezra opened this issue Jul 28, 2010 · 4 comments
Closed

Parameterized blueprints #45

pezra opened this issue Jul 28, 2010 · 4 comments

Comments

@pezra
Copy link

pezra commented Jul 28, 2010

I would be nice to define named blueprints with regexp patterns. The actually blueprint name used could affect the behavior of the blueprint. For example,

Post.make(:with_3_comments)

Doing this with a pattern would allow for large classes of similar blueprints to be supported with very succinct definition. The blueprint for the above would look something like

Post.blueprint(/with_(\d+)_comments/) do |num_comments|
  # ...
  comments(num_comments.to_i)
end

Would a patch implementing this be accepted?

@notahat
Copy link
Owner

notahat commented Jul 30, 2010

Hmmm, not sure. It'd be a mess to implement on top of the current named blueprints and caching mechanism.

I'd rather find some way to pass stuff like this in as extra arguments, but I'm not sure how to fit that in with the existing arguments to make.

@pezra
Copy link
Author

pezra commented Aug 2, 2010

Are you thinking something like:

Post.blueprint(:with_comments, :blueprint_params => [:num_comments]) do |params|
  # ...
  comments(params[:num_comments].to_i)
end

Post.make(:with_comments, :num_comments => 3)

That syntax for making the objects feels less clear to me. Keeping pecs/tests as clear and concise as possible is paramount for me. However, having this functionality is more important than the syntax. If you have a strong preference i am open to implementing that.

I haven't looked at the internals of the caching mechanism yet. I'll take a look soon an see if i can see an approach to caching the results of parameterized blueprints.

@inspire22
Copy link

the randexp gem would work great for this, check it out

@notahat
Copy link
Owner

notahat commented Jun 19, 2011

The caching mechanism is now gone, but this still all feels a bit too magic to me. I'd just make some nice helper methods that wrap calls to Machinist if I was doing the same thing.

That said, feel free to fork and give it a go. You may come up with something that surprises me, and even if you don't, there's no harm in having a fork that meets your needs.

Or you can always make another gem that extends Machinist. (I'm encouraging the guys working on DataMapper support to make a machinist-dm gem, for example.)

@notahat notahat closed this as completed Jun 19, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants