From 904a32331073b5840eb2742d5178d7ca58d91f97 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 12 Aug 2020 14:15:45 -0700 Subject: Optimize requires for non-omnibus installs require is quite slow in Ruby and doing requires for things you've already required is also slow. We've used this simple hack in Chef to speed up our requires. In the omnibus installs we patch how rubygems works to make this somewhat pointless, but this will help non-omnibus installs Signed-off-by: Tim Smith --- lib/mixlib/config.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb index d57a44a..1508f5b 100644 --- a/lib/mixlib/config.rb +++ b/lib/mixlib/config.rb @@ -69,7 +69,7 @@ module Mixlib # === Parameters # filename:: A filename to read from def from_yaml(filename) - require "yaml" + require "yaml" unless defined?(YAML) from_hash(YAML.load(IO.read(filename))) end @@ -78,12 +78,12 @@ module Mixlib # === Parameters # filename:: A filename to read from def from_json(filename) - require "json" + require "json" unless defined?(JSON) from_hash(JSON.parse(IO.read(filename))) end def from_toml(filename) - require "tomlrb" + require "tomlrb" unless defined?(Tomlrb) from_hash(Tomlrb.parse(IO.read(filename), symbolize_keys: true)) end -- cgit v1.2.1