Skip to content

Commit

Permalink
Check that Bundler is really set up before loading plugins with it
Browse files Browse the repository at this point in the history
Requiring 'bundler/setup' won't do much if the Gemfile is not found,
leaving `Bundler.require` undefined.
  • Loading branch information
tmatilai committed Aug 31, 2017
1 parent 763b5a3 commit 9deb634
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/tf
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 8 additions & 4 deletions lib/yle_tf/plugin/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down

0 comments on commit 9deb634

Please sign in to comment.