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

with_env behaviour with multiple environment variables #223

Closed
jennifersmith opened this issue Jan 12, 2015 · 4 comments
Closed

with_env behaviour with multiple environment variables #223

jennifersmith opened this issue Jan 12, 2015 · 4 comments

Comments

@jennifersmith
Copy link

I see that recently @dg-ratiodata added a helpful method with_env to Aruba::API (#188) that allows you to run a block with environment variables set which are then restored back to original values.

However, the current implementation seems to run the block once for each env var you pass into the hash.

    def with_env(env = {}, &block)
      env.each do |k,v|
        set_env k, v
        block.call
        restore_env
      end
    end

Is this the intended behaviour?

Context: I want to set a series of env vars before running my process all together,

I can achieve this by calling the underlying methods directly, but I wondered whether you would be happy for me to change this method to set all the vars just once and then call the block. Something like:

    def with_env(env = {}, &block)
      env.each do |k,v|
        set_env k, v
      end

      block.call
      restore_env
    end

Appreciate that this breaks existing behaviour and so might be a breaking change for some people - so I would be happy to rename this method or use an alternative approach.

@ghost
Copy link

ghost commented Jan 12, 2015

Good question, why I implemented it this way. 😄 But I think your implementation was the one I had in mind.

The only thing I would change is the style of the each-loop.

env.each { |k,v| set_env k, v }

@jarl-dk Should he provide a PR?

@ghost
Copy link

ghost commented Jan 14, 2015

@jarl-dk Should he provide a PR?

@jarl-dk Should she provide a PR?
Sorry for that @jennifersmith

@jarl-dk
Copy link
Member

jarl-dk commented Jan 14, 2015

Thanks for this.

@jennifersmith
Copy link
Author

Ha no worries on both counts, thanks for addressing this (and for a very
useful library)
On 15 Jan 2015 00:37, "Jarl Friis" notifications@github.com wrote:

Thanks for this.


Reply to this email directly or view it on GitHub
#223 (comment).

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

2 participants