Allow meta-gems to be required #5

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@aripollak

The existing code doesn't restore the behavior of the "gem" method, which means that meta-gems like irbtools don't work even after running it. This fixes the problem, and it should allow you to use meta-gems in ~/.irbrc even when using bundler.

@aripollak aripollak Allow meta-gems to be required
The existing code doesn't restore the behavior of the "gem" method, which means that meta-gems like irbtools don't work even after running it. This fixes the problem.
5da8e8c
@ConradIrwin
Owner

Hi @aripollak.

Thanks for this pull-request. I'm not sure that alias gem require has the desired effect in this case. I think we need to actually reinstate the correct gem method: 866637e.

Can you please confirm that v0.4 fixes this problem for you?

Thanks!
Conrad

@aripollak

Not sure, but the alias works fine for me since RubyGems' require (which is restored by custom_require.rb) should be equivalent to gem().

@ConradIrwin
Owner

If only it were :).

127868:/0/ruby/pry-rescue[master].$ pry
[1] pry(main)> $ require

From: /home/conrad/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb @ line 34:
Number of lines: 31
Owner: Kernel
Visibility: private

def require path
  if Gem.unresolved_deps.empty? then
    gem_original_require path
  else
    spec = Gem::Specification.find { |s|
      s.activated? and s.contains_requirable_file? path
    }

    unless spec then
      found_specs = Gem::Specification.find_in_unresolved path
      unless found_specs.empty? then
        found_specs = [found_specs.last]
      else
        found_specs = Gem::Specification.find_in_unresolved_tree path
      end

      found_specs.each do |found_spec|
        found_spec.activate
      end
    end

    return gem_original_require path
  end
rescue LoadError => load_error
  if load_error.message.start_with?("Could not find") or
      (load_error.message.end_with?(path) and Gem.try_activate(path)) then
    return gem_original_require(path)
  end

  raise load_error
end
[2] pry(main)> $ gem

From: /home/conrad/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/rubygems.rb @ line 1228:
Number of lines: 6
Owner: Kernel
Visibility: private

def gem(gem_name, *requirements) # :doc:
  skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
  raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
  spec = Gem::Dependency.new(gem_name, *requirements).to_spec
  spec.activate if spec
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment