Ask Your Question
0

define ordering for resources created by loop

asked 2014-03-21 11:58:43 -0500

pascal gravatar image

I have a project with a complicated configuration where quiet often resources are created with loops (yes the future parser) over nested hashes from YAML sources. Now I stumbled over a particular one, which needs one of its resources managed before the rest of the hash can be managed. I'd like to write something like res[ 'a' ] -> res[ Hash.rest ]. I do not think the actual solution is a oneliner, but I need the right side of the ordering relation to have only the res declarations from the hash, not from any other places where the same type is ... (more)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-03-26 11:37:10 -0500

pascal gravatar image

I found a solution, I put the simpified version below:

My main problem was, that the keys and values are only partly known inside the modules: { <lable>-foo-<version> => { more data} }. And foo is not garanteed to be part of the hash. The solution was</version></lable>

x = keys(hash).select |k| { k =~ /-foo-/ }
unless empty(x) {
  y = keys(hash).reject |k| { k =~ /-foo-/ }
  Res[ x ] -> Res[ y ]
}

I had to write an additional compare function because of my complexer data, but the concept is the same.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-03-21 11:58:43 -0500

Seen: 59 times

Last updated: Mar 26 '14