DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

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

09.06.2005
| 3300 views |
  • submit to reddit
        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'