lib/eac_launcher/ruby/gem/build.rb in eac_launcher-0.3.1 vs lib/eac_launcher/ruby/gem/build.rb in eac_launcher-0.3.2

- old
+ new

@@ -44,15 +44,13 @@ isolated_build_gem end end def isolated_build_gem - old_bundle_gemfile = ENV['BUNDLE_GEMFILE'] - ENV['BUNDLE_GEMFILE'] = nil - EacRubyUtils::Envs.local.command('gem', 'build', gemspec_file).execute! - ensure - ENV['BUNDLE_GEMFILE'] = old_bundle_gemfile + on_clean_ruby do + EacRubyUtils::Envs.local.command('gem', 'build', gemspec_file).execute! + end end def check_gem_empty_size Dir.mktmpdir do |dir| Dir.chdir dir do @@ -81,9 +79,33 @@ def check_gem_version spec = ::EacLauncher::Ruby::Gem::Specification.new(gemspec_file) return if ::File.basename(output_file, '.gem') == spec.full_name raise("Builded gem is not the same version of gemspec (#{spec}, #{output_file})") + end + + def bundle_dependencies + gemfile = @gem_root.subpath('Gemfile') + return unless ::File.exist?(gemfile) + Dir.chdir(@gem_root) do + EacRubyUtils::Envs.local.command('bundle', 'install').execute! + end + end + + def on_clean_ruby + on_clear_envvars('BUNDLE', 'RUBY') { yield } + end + + def on_clear_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 } if old_values + end + + def envvars_starting_with(start_with_vars) + ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } } end end end end end