Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow meta-gems to be required #5

Closed
wants to merge 1 commit into from
Closed

Allow meta-gems to be required #5

wants to merge 1 commit into from

Conversation

aripollak
Copy link

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.

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.
@ConradIrwin
Copy link
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
Copy link
Author

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
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants