Sha256: 3fde5fcc37b202d754f55122106b0d6d31b8d0d0327674d790007ca433b1ece8

Contents?: true

Size: 830 Bytes

Versions: 12

Compression:

Stored size: 830 Bytes

Contents

module FeduxOrg
  module Stdlib
    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
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.3.2 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.3.0 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.2.1 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.1.3 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.1.2 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.1.1 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.1.0 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.0.39 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.0.38 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.0.37 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.0.36 lib/fedux_org/stdlib/environment.rb
fedux_org-stdlib-0.0.35 lib/fedux_org/stdlib/environment.rb