open_gem icon indicating copy to clipboard operation
open_gem copied to clipboard

undefined method `source_index' for Gem:Module

Open alexch opened this issue 11 years ago • 8 comments

In the latest RubyGems (2.2.1), this plugin fails:

ERROR:  While executing gem ... (NoMethodError)
    undefined method `source_index' for Gem:Module

This is a shame since I love using gem open (at least when I'm not using RubyMine, which opens the gem source for you with a command-click). I'm pretty sure it's because the RubyGems team refactored the internals, but it's definitely still possible to find the location of a gem since they added gem which. So all we have to do (knock wood) is look in the source to see what which is calling and update open_gem to use it instead of source_index.

alexch avatar Feb 07 '14 14:02 alexch

Hey Alex, sorry I sat on this for a while. If you happen to find a fix, I'll pull it, especially if it is backwards compatible with previous versions of RubyGems.

Personally, I would recommend trying out Qwandryhttps://github.com/adamsanderson/qwandry/, which is more general and will open files in the standard library as well as gems. That's where I'm focussing my time these days ;)

On Fri, Feb 7, 2014 at 6:04 AM, Alex Chaffee [email protected]:

In the latest RubyGems (2.2.1), this plugin fails:

ERROR: While executing gem ... (NoMethodError) undefined method `source_index' for Gem:Module

This is a shame since I love using gem open (at least when I'm not using RubyMine, which opens the gem source for you with a command-click). I'm pretty sure it's because the RubyGems team refactored the internals, but it's definitely still possible to find the location of a gem since they added gem which. So all we have to do (knock wood) is look in the source to see what which is calling and update open_gem to use it instead of source_index.

Reply to this email directly or view it on GitHubhttps://github.com/adamsanderson/open_gem/issues/17 .

adamsanderson avatar Feb 20 '14 16:02 adamsanderson

Alright, I'll take a stab at it. (Unit testing against different versions of rubygems will be a nightmare...)

Maybe a new "gem open" plugin should be part of qw? Or a new open_gem should just delegate to qw?

alexch avatar Feb 21 '14 13:02 alexch

Proof of concept is easy: in common_options.rb:

def get_spec(name)

  # dep = Gem::Dependency.new(name, options[:version])
  # specs = Gem.source_index.search(dep)

  specs = Gem::Specification.find_all { |s|
    s.name.include? name
  }

Actually building the gem -- not to mention running tests -- remains elusive.

...and here's some (ugly) code that honors the options:

  specs = Gem::Specification.find_all do |s|
    (options[:exact] ? s.name == name : 
      (name.is_a?(Regexp) ? s.name =~ name : s.name.include?(name))) and 
     (options[:version] ? options[:version].satisfied_by?(s.version) : true)
  end

alexch avatar Feb 21 '14 14:02 alexch

Actually Alex, if we make that update, we can just bump the minimum supported version of rubygems, so don't worry about prior versions as long as the gemspec gets updated.

On Fri, Feb 21, 2014 at 6:51 AM, Alex Chaffee [email protected]:

Proof of concept is easy: in common_options.rb:

def get_spec(name)

dep = Gem::Dependency.new(name, options[:version])

specs = Gem.source_index.search(dep)

specs = Gem::Specification.find_all { |s| s.name.include? name }

Actually building the gem -- not to mention running tests -- remains elusive.

...and here's some (ugly) code that honors the options:

specs = Gem::Specification.find_all do |s| (options[:exact] ? s.name == name : (name.is_a?(Regexp) ? s.name =~ name : s.name.include?(name))) and (options[:version] ? options[:version].satisfied_by?(s.version) : true) end

Reply to this email directly or view it on GitHubhttps://github.com/adamsanderson/open_gem/issues/17#issuecomment-35736587 .

adamsanderson avatar Feb 21 '14 18:02 adamsanderson

Looks like the find_all method goes back at least as far as 1.8.0 (May 2011) so that shouldn't ruffle too many feathers. But is it even possible to check the rubygems version? I suppose we could put in a check against Gem::VERSION but I don't think rubygems itself lets you specify a minimum rubygems version...

I dusted off an old 1.9 ruby install and I'm having much better luck building it. I'll submit a PR shortly.

alexch avatar Feb 21 '14 19:02 alexch

I think you should be able to update the gemspec with s.rubygems_version = %q{1.8.0}. Barring that perhaps we can specify an explicit dependency on rubygems 1.8.0 with the add_dependency method in the gemspec. I should tear out Jeweler as well, it doesn't really add anything...

On Fri, Feb 21, 2014 at 11:03 AM, Alex Chaffee [email protected]:

Looks like the find_all method goes back at least as far as 1.8.0 (May 2011) so that shouldn't ruffle too many feathers. But is it even possible to check the rubygems version? I suppose we could put in a check against Gem::VERSION but I don't think rubygems itself lets you specify a minimum rubygems version...

I dusted off an old 1.9 ruby install and I'm having much better luck building it. I'll submit a PR shortly.

Reply to this email directly or view it on GitHubhttps://github.com/adamsanderson/open_gem/issues/17#issuecomment-35761899 .

adamsanderson avatar Feb 21 '14 19:02 adamsanderson

rubygems_version is not a check; it's just recording what version created it (or installed it? docs are vague). add_dependency wouldn't work since rubygems is not itself a gem (rubygems-update is but there's no guarantee that will still be around after an update).

Aha! Looks like there's an (ahem) undocumented required_rubygems_version attribute now that does what we want.

alexch avatar Feb 21 '14 20:02 alexch

https://github.com/rubygems/guides/issues/78 :-)

alexch avatar Feb 23 '14 14:02 alexch