module Asciidoctor::Helpers
def require_library name, gem_name = true, on_failure = :abort
Otherwise, if on_failure is :warn, Kernel#warn is called with an appropriate message and nil returned.
Otherwise, if on_failure is :abort, Kernel#raise is called with an appropriate message.
Returns The [Boolean] return value of Kernel#require if the library can be loaded.
on_failure - a Symbol that indicates how to handle a load failure (:abort, :warn, :ignore) (default: :abort)
(default: true)
or the String name of the RubyGem if it differs from the library name
gem_name - a Boolean that indicates whether this library is provided by a RubyGem,
name - the String name of the library to require.
specified, the message communicates that a required gem is not available.
aborted or functionality is disabled, respectively. If a gem_name is
on_failure is :warn to communicate to the user that processing is being
passes a message to Kernel#raise if on_failure is :abort or Kernel#warn if
Kernel#require. Rescues the LoadError if the library is not available and
Attempts to load the library specified in the first argument using the
Public: Require the specified library using Kernel#require.
def require_library name, gem_name = true, on_failure = :abort require name rescue ::LoadError include Logging unless include? Logging if gem_name gem_name = name if gem_name == true case on_failure when :abort details = $!.path == gem_name ? '' : %[ (reason: #{$!.path ? %(cannot load '#{$!.path}') : $!.message})] raise ::LoadError, %(asciidoctor: FAILED: required gem '#{gem_name}' is not available#{details}. Processing aborted.) when :warn details = $!.path == gem_name ? '' : %[ (reason: #{$!.path ? %(cannot load '#{$!.path}') : $!.message})] logger.warn %(optional gem '#{gem_name}' is not available#{details}. Functionality disabled.) end else case on_failure when :abort raise ::LoadError, %(asciidoctor: FAILED: #{$!.message.chomp '.'}. Processing aborted.) when :warn logger.warn %(#{$!.message.chomp '.'}. Functionality disabled.) end end nil end