Sha256: 2a76fb97e61c7dd2d3401db889d4f27029f4c0259b169296c098142dd168d810

Contents?: true

Size: 545 Bytes

Versions: 14

Compression:

Stored size: 545 Bytes

Contents

# frozen_string_literal: true

module EacRubyUtils
  class << self
    def on_clean_ruby_environment
      on_clean_envvars('BUNDLE', 'RUBY') { yield }
    end

    private

    def on_clean_envvars(*start_with_vars)
      old_values = envvars_starting_with(start_with_vars)
      old_values.keys.each { |k| ENV.delete(k) }
      yield
    ensure
      old_values&.each { |k, v| ENV[k] = v }
    end

    def envvars_starting_with(start_with_vars)
      ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } }
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
eac_ruby_utils-0.28.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
ehbrs-tools-0.5.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.27.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.26.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.25.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
ehbrs-tools-0.3.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.24.1 lib/eac_ruby_utils/on_clean_ruby_environment.rb
ehbrs-tools-0.3.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.24.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.23.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.22.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.21.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.20.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb
eac_ruby_utils-0.19.0 lib/eac_ruby_utils/on_clean_ruby_environment.rb