Making config.gem in Rails 2.3.x allow you to install from a direct url or the local filesystem

If you are on Rails 2.3.x (pre-Bundler) and want to organize some of your shared functionality into gems, but they are for internal use only, you could set-up a private gem server and point the :source at this server.  And then you could deal with authentication, and then…

Or as a quick hack you could just allow for config.gem to reference the gemfile directly, which would then mean ‘rake gems:install’ would work, even if the gem were stored locally, or on a file-server, etc.  Also useful as you could then just point at a .gem file on github.

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 
## require in config/environment.rb before init starts
#require ‘config/add_explicit_path_to_config_gem’
#Rails::Initializer.run do |config|
#config.gem ‘my_gem’, :version => ‘0.0.1’, :explicit_path => “#{RAILS_ROOT}/vendor/local_gemfiles/my_gem-0.0.1.gem” #or
#config.gem ‘my_gem’, :version => ‘0.0.1’, :explicit_path => “http://github.com/myname/myrepo/raw/master/mygem.gem” #or
 
module Rails
  class GemDependency
    def initialize_with_explicit_path(name, options = {})
      @explicit_path = options[:explicit_path]
      initialize_without_explicit_path(name, options = {})
    end
    alias_method_chain :initialize, :explicit_path
    
  private
  
    def install_command
      cmd = %w(install) « (@explicit_path || name)
      cmd « “—version” « %(“#{requirement.to_s}”) if requirement
      cmd « “—source” « @source if @source
      cmd
    end
  end
end

Posted via web from a timocracy of one | Comment »

Notes

  1. timocratic posted this