Over a million developers have joined DZone.

Require A Gem Or Lib In /vendor In A Ruby On Rails App

·
checks for the existence of a lib in /vendor/YOURLIB/lib and requires that.  otherwise, it requires the gem.

def require_vendor_or_gem(*libs)
  libs.each do |lib|
    if File.directory?("#{RAILS_ROOT}/vendor/#{lib}/lib")
      $:.unshift("#{RAILS_ROOT}/vendor/#{lib}/lib")
      require_dependency lib.to_s
    else
      require_gem lib.to_s
    end
  end
end

require_vendor_or_gem 'sentry', 'money'


Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}