Sha256: 6530d5ecec13315b00f04447c26c30dbcf37bddba68c03f20ae60f1d45b1f1ed

Contents?: true

Size: 843 Bytes

Versions: 64

Compression:

Stored size: 843 Bytes

Contents

# encoding: utf-8
module FeduxOrgStdlib
  module Environment

    # Set environment variable for code block
    #
    # @param [Hash] new_environment_variables
    #   the variables which should be set for that environment
    #
    # @param [Hash] options
    #   options for environment manipulation
    #
    # @option options [True,False] :clear
    #   Should the environment clear before merge? 
    #
    # @yield
    #   the block which should be run which the change environment
    def isolated_environment(new_environment_variables, options={}, &block)
      old_environment = ENV.to_hash

      ENV.clear if options[:clear] == true
      ENV.update new_environment_variables

      block.call
    ensure
      ENV.clear 
      ENV.update old_environment
    end

    alias_method :with_environment, :isolated_environment
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.7.21 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.20 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.19 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.18 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.17 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.16 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.15 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.14 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.12 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.11 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.10 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.8 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.7 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.6 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.5 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.4 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.3 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.2 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.1 lib/fedux_org_stdlib/environment.rb
fedux_org-stdlib-0.7.0 lib/fedux_org_stdlib/environment.rb