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:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}