diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2020-08-03 16:35:08 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2020-08-03 16:35:08 -0700 |
commit | f97ea73bdda30563ae9ddc5fc771e00ca8447a65 (patch) | |
tree | 08906732900920ec3fe58d72d31d483cfdbcc438 | |
parent | 955a4a5685026f28d417d8977784a6ca89ff0279 (diff) | |
download | ohai-f97ea73bdda30563ae9ddc5fc771e00ca8447a65.tar.gz |
Faster ruby language pluginlcg/faster-rubylang-plugin
This drops two additional shell outs to run ruby.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/ohai/plugins/ruby.rb | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/lib/ohai/plugins/ruby.rb b/lib/ohai/plugins/ruby.rb index 11528724..d83d8f72 100644 --- a/lib/ohai/plugins/ruby.rb +++ b/lib/ohai/plugins/ruby.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,6 +43,8 @@ Ohai.plugin(:Ruby) do host_vendor: "RbConfig::CONFIG['host_vendor']", bin_dir: "RbConfig::CONFIG['bindir']", ruby_bin: "::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])", + gem_bin: "::File.join(RbConfig::CONFIG['bindir'], ::Gem.default_exec_format % 'gem')", + gems_dir: "::Gem.dir", } # Create a query string from above hash @@ -52,25 +54,12 @@ Ohai.plugin(:Ruby) do end # Query the system ruby - result = run_ruby "puts %Q(#{env_string})" + result = run_ruby "require 'rubygems'; puts %Q(#{env_string})" # Parse results to plugin hash result.split(",").each do |entry| key, value = entry.split("=") languages[:ruby][key.to_sym] = value || "" end - - # Perform one more (conditional) query - bin_dir = languages[:ruby][:bin_dir] - ruby_bin = languages[:ruby][:ruby_bin] - gem_binaries = [ - run_ruby("require 'rubygems'; puts ::Gem.default_exec_format % 'gem'"), - "gem", - ].map { |bin| ::File.join(bin_dir, bin) } - gem_binary = gem_binaries.find { |bin| ::File.exist? bin } - if gem_binary - languages[:ruby][:gems_dir] = run_ruby "puts %x{#{ruby_bin} #{gem_binary} env gemdir}.chomp!" - languages[:ruby][:gem_bin] = gem_binary - end end end |