From 9deb63455cf74e7ced5c5eb2a0ee892e344be2f3 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 31 Aug 2017 10:37:16 +0300 Subject: [PATCH] Check that Bundler is really set up before loading plugins with it Requiring 'bundler/setup' won't do much if the Gemfile is not found, leaving `Bundler.require` undefined. --- bin/tf | 2 +- lib/yle_tf/plugin/loader.rb | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/tf b/bin/tf index b82873a..abd2fcf 100755 --- a/bin/tf +++ b/bin/tf @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require 'bundler/setup' if File.exist? File.expand_path('../../Gemfile', __FILE__) +require 'bundler/setup' if File.exist?(File.expand_path('../../Gemfile', __FILE__)) require 'yle_tf/cli' cli = YleTf::CLI.new(ARGV) diff --git a/lib/yle_tf/plugin/loader.rb b/lib/yle_tf/plugin/loader.rb index c7823aa..cdbede8 100644 --- a/lib/yle_tf/plugin/loader.rb +++ b/lib/yle_tf/plugin/loader.rb @@ -19,10 +19,10 @@ def self.load_core_plugins end def self.load_bundler_plugins - if defined?(Bundler) - print_bundler_plugin_list if Logger.debug? - Bundler.require(BUNDLER_PLUGIN_GROUP) - end + return if !bundler_set_up? + + Logger.debug { print_bundler_plugin_list } + Bundler.require(BUNDLER_PLUGIN_GROUP) end def self.load_user_plugins @@ -47,6 +47,10 @@ def self.user_plugins ENV.fetch('TF_PLUGINS', '').split(/[ ,]+/) end + def self.bundler_set_up? + defined?(Bundler) && Bundler.respond_to?(:require) + end + def self.print_bundler_plugin_list plugins = bundler_plugins if !plugins.empty?