Deleting an element in an attribute?

I’m probably not using the right terms, but lets’ say I have the following:

set[:packages_install_specific] = [
[“js”,“1.70-8”],
[“icu”,“3.6-5.16.1”],
[“libicu”,“3.6-5.16.1”],
[“libicu-devel”,“3.6-5.16.1”]
]

The attrs looks like:
{
“normal”: {
“packages_install_specific”: [
[
“js”,
“1.70-8”
],
[
“icu”,
“3.6-5.16.1”
],
[
“libicu”,
“3.6-5.16.1”
],
[
“libicu-devel”,
“3.6-5.16.1”
]
]

Is it possible to delete the tuple [“libicu-devel”,“3.6-5.16.1”] programmatically in a recipe? I’ve tried using:

node.normal_attrs[:packages_install_specific].delete(:libicu-devel) rescue nil

But I probably can’t refer to it as a key…Can someone shed some light on this? If someone can forward me to some docs I’d greatly appreciate it. Running 0.9.x (8 I believe), thanks in advance!

-Robert

What if you make it a hash instead of a list?

set[:packages_install_specific] = {
"js" => "1.70-8",
"icu" => "3.6-5.16.1",
...
}

Then you can do, eg,
node.normal_attrs[:packages_install_specific].delete("js")

On Wed, Feb 1, 2012 at 7:05 PM, Robert Keng robert@sv.comcast.com wrote:

I'm probably not using the right terms, but lets' say I have the
following:

set[:packages_install_specific] = [
["js","1.70-8"],
["icu","3.6-5.16.1"],
["libicu","3.6-5.16.1"],
["libicu-devel","3.6-5.16.1"]
]

The attrs looks like:
{
"normal": {
"packages_install_specific": [
[
"js",
"1.70-8"
],
[
"icu",
"3.6-5.16.1"
],
[
"libicu",
"3.6-5.16.1"
],
[
"libicu-devel",
"3.6-5.16.1"
]
]

...

Is it possible to delete the tuple ["libicu-devel","3.6-5.16.1"]
programmatically in a recipe? I've tried using:

node.normal_attrs[:packages_install_specific].delete(:libicu-devel)
rescue nil

But I probably can't refer to it as a key...Can someone shed some light
on this? If someone can forward me to some docs I'd greatly appreciate it.
Running 0.9.x (8 I believe), thanks in advance!

-Robert

--
Ian Marlier | Senior Systems Engineer
Brightcove, Inc.
One Cambridge Center, 12th Floor, Cambridge, MA 02142
imarlier@brightcove.com

... or you can modify the array

node.normal_attrs[:packages_install_specific].reject! {|p| p[0] == "
libicu-devel" }

--max

On Wed, Feb 1, 2012 at 4:16 PM, Ian Marlier imarlier@brightcove.com wrote:

What if you make it a hash instead of a list?

set[:packages_install_specific] = {
"js" => "1.70-8",
"icu" => "3.6-5.16.1",
...
}

Then you can do, eg,
node.normal_attrs[:packages_install_specific].delete("js")

On Wed, Feb 1, 2012 at 7:05 PM, Robert Keng robert@sv.comcast.com wrote:

I'm probably not using the right terms, but lets' say I have the
following:

set[:packages_install_specific] = [
["js","1.70-8"],
["icu","3.6-5.16.1"],
["libicu","3.6-5.16.1"],
["libicu-devel","3.6-5.16.1"]
]

The attrs looks like:
{
"normal": {
"packages_install_specific": [
[
"js",
"1.70-8"
],
[
"icu",
"3.6-5.16.1"
],
[
"libicu",
"3.6-5.16.1"
],
[
"libicu-devel",
"3.6-5.16.1"
]
]

...

Is it possible to delete the tuple ["libicu-devel","3.6-5.16.1"]
programmatically in a recipe? I've tried using:

node.normal_attrs[:packages_install_specific].delete(:libicu-devel)
rescue nil

But I probably can't refer to it as a key...Can someone shed some light
on this? If someone can forward me to some docs I'd greatly appreciate it.
Running 0.9.x (8 I believe), thanks in advance!

-Robert

--
Ian Marlier | Senior Systems Engineer
Brightcove, Inc.
One Cambridge Center, 12th Floor, Cambridge, MA 02142
imarlier@brightcove.com

On Thu, Feb 2, 2012 at 1:05 AM, Robert Keng robert@sv.comcast.com wrote:

I'm probably not using the right terms, but lets' say I have the following:

set[:packages_install_specific] = [
["js","1.70-8"],
["icu","3.6-5.16.1"],
["libicu","3.6-5.16.1"],
["libicu-devel","3.6-5.16.1"]
]

The attrs looks like:
{
"normal": {
"packages_install_specific": [
[
"js",
"1.70-8"
],
[
"icu",
"3.6-5.16.1"
],
[
"libicu",
"3.6-5.16.1"
],
[
"libicu-devel",
"3.6-5.16.1"
]
]

...

Is it possible to delete the tuple ["libicu-devel","3.6-5.16.1"]
programmatically in a recipe? I've tried using:

There are more idiomatic ways that are more compact, but this is nice
and readable:

packages = node[:packages_install_specific]

packages.reject! do |name, version|
name == "libicu-devel" && version == "3.6-5.16.1"
end

node[:packages_install_specific] = packages

Andrea

Thx for the suggestions Ian/Max, will def look at using hashes instead, but was able to incorporate Max’s suggestion in our recipe for now, it works great, again thanks!

-Robert


From: likonar@gmail.com [likonar@gmail.com] on behalf of Max Gorbul [max@gorbul.net]
Sent: Wednesday, February 01, 2012 4:20 PM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Deleting an element in an attribute?

… or you can modify the array

node.normal_attrs[:packages_install_specific].reject! {|p| p[0] == “libicu-devel” }

–max

On Wed, Feb 1, 2012 at 4:16 PM, Ian Marlier <imarlier@brightcove.commailto:imarlier@brightcove.com> wrote:
What if you make it a hash instead of a list?

set[:packages_install_specific] = {
“js” => “1.70-8”,
“icu” => “3.6-5.16.1”,

}

Then you can do, eg, node.normal_attrs[:packages_install_specific].delete(“js”)

On Wed, Feb 1, 2012 at 7:05 PM, Robert Keng <robert@sv.comcast.commailto:robert@sv.comcast.com> wrote:
I’m probably not using the right terms, but lets’ say I have the following:

set[:packages_install_specific] = [
[“js”,“1.70-8”],
[“icu”,“3.6-5.16.1”],
[“libicu”,“3.6-5.16.1”],
[“libicu-devel”,“3.6-5.16.1”]
]

The attrs looks like:
{
“normal”: {
“packages_install_specific”: [
[
“js”,
“1.70-8”
],
[
“icu”,
“3.6-5.16.1”
],
[
“libicu”,
“3.6-5.16.1”
],
[
“libicu-devel”,
“3.6-5.16.1”
]
]

Is it possible to delete the tuple [“libicu-devel”,“3.6-5.16.1”] programmatically in a recipe? I’ve tried using:

node.normal_attrs[:packages_install_specific].delete(:libicu-devel) rescue nil

But I probably can’t refer to it as a key…Can someone shed some light on this? If someone can forward me to some docs I’d greatly appreciate it. Running 0.9.x (8 I believe), thanks in advance!

-Robert


Ian Marlier | Senior Systems Engineer
Brightcove, Inc.
One Cambridge Center, 12th Floor, Cambridge, MA 02142
imarlier@brightcove.commailto:imarlier@brightcove.com