Of course, you'd need more code if you wanted it to be more generally useful, to handle attributes, notifies, etc.
It seems overkillish to me, though. I find lines like "%w<foo bar baz>.each { |p| package p }" to be pretty short, sweet and clear.
On Wednesday, August 31, 2011, Matt Palmer <
" target="_blank">
> wrote:
> I'm getting my first chef recipe in order, a simple one to prep a
> workstation -- which is mostly "install this giant list of packages".
>
> I was surprised to find that the simple, obvious way to do this:
>
> package %w{foo bar baz} do
> action :install
> end
>
> Didn't work. Resources don't accept an array as the namevar to do the
> obvious thing. Instead, I've got to do either:
>
> package "foo" do
> action :install
> end
>
> package "bar" do
> action :install
> end
>
> package "baz" do
> action :install
> end
>
> Which is ridiculously verbose, or else:
>
> %w{foo bar baz}.each do |pkg|
> package pkg do
> action :install
> end
> end
>
> Which doesn't do anything for my "but you don't need to learn *much*
> Ruby" claims to the rest of the team, and still isn't as compact and
> clean as it could be.
>
> Am I missing something obvious, or is one of the above options really
> the recommended way to create big lists of resources?
>
> Thanks,
> - Matt
>