Module: J1::External
- Defined in:
- lib/j1/external.rb
Class Method Summary collapse
-
.blessed_gems ⇒ Object
Gems that, if installed, should be loaded.
-
.require_if_present(names) ⇒ Object
Require a gem or file if it’s present, otherwise silently fail.
-
.require_with_graceful_fail(names) ⇒ Object
Require a gem or gems.
Class Method Details
.blessed_gems ⇒ Object
Gems that, if installed, should be loaded. Usually contain subcommands.
8 9 10 11 12 13 |
# File 'lib/j1/external.rb', line 8 def blessed_gems %w( jekyll-docs jekyll-import ) end |
.require_if_present(names) ⇒ Object
Require a gem or file if it’s present, otherwise silently fail.
names - a string gem name or array of gem names
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/j1/external.rb', line 20 def require_if_present(names) Array(names).each do |name| begin require name rescue LoadError J1.logger.debug "Couldn't load #{name}. Skipping." yield(name) if block_given? false end end end |
.require_with_graceful_fail(names) ⇒ Object
Require a gem or gems. If it’s not present, show a very nice error message that explains everything and is much more helpful than the normal LoadError.
names - a string gem name or array of gem names
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/j1/external.rb', line 39 def require_with_graceful_fail(names) Array(names).each do |name| begin J1.logger.debug "Requiring:", name.to_s require name rescue LoadError => e J1.logger.error "Dependency Error:", <<-MSG Yikes! It looks like you don't have #{name} or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: '#{e.}' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/! MSG raise Jekyll::Errors::MissingDependencyException, name end end end |