instance method require_library_or_gem

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v3.1.12

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12

Signature

require_library_or_gem(library_name)

Require a library with fallback to RubyGems. Warnings during library loading are silenced to increase signal/noise for application warnings.

Parameters

library_name req
Source
# File activesupport/lib/active_support/core_ext/kernel/requires.rb, line 4
  def require_library_or_gem(library_name)
    silence_warnings do
      begin
        require library_name
      rescue LoadError => cannot_require
        # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
        begin
          require 'rubygems'
        rescue LoadError => rubygems_not_installed
          raise cannot_require
        end
        # 2. Rubygems is installed and loaded. Try to load the library again
        begin
          require library_name
        rescue LoadError => gem_not_installed
          raise cannot_require
        end
      end
    end
  end

Defined in activesupport/lib/active_support/core_ext/kernel/requires.rb line 4 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Kernel

Type at least 2 characters to search.

↑↓ navigate · open · esc close