Sha256: f5ca318688f7db0ccb615bd5e0d2edee7092ab348ed95ebbf33feb105f4cba80

Contents?: true

Size: 941 Bytes

Versions: 53

Compression:

Stored size: 941 Bytes

Contents

require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/module/deprecation'

module Kernel
  # Require a library with fallback to RubyGems.  Warnings during library
  # loading are silenced to increase signal/noise for application warnings.
  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
  deprecate :require_library_or_gem
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
activesupport-3.1.12 lib/active_support/core_ext/kernel/requires.rb
activesupport-3.1.11 lib/active_support/core_ext/kernel/requires.rb
activesupport-3.1.10 lib/active_support/core_ext/kernel/requires.rb
activesupport-3.1.9 lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
activesupport-3.1.8 lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
activesupport-3.1.7 lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb
activesupport-3.1.6 lib/active_support/core_ext/kernel/requires.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/kernel/requires.rb