Skip to content

Commit

Permalink
Merge pull request #19 from dgutov/gem_root
Browse files Browse the repository at this point in the history
Pry::MethodInfo.gem_root: return gem root instead of ruby root
  • Loading branch information
kyrylo committed Mar 8, 2014
2 parents 2914415 + d68da0c commit 7e1682c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pry-doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def self.method_host(meth)
# FIXME: this is unnecessarily limited to ext/ and lib/ folders
# @return [String] The root folder of a given gem directory.
def self.gem_root(dir)
dir.split(/\/(?:lib|ext)(?:\/|$)/).first
if index = dir.rindex(/\/(?:lib|ext)(?:\/|$)/)
dir[0..index-1]
end
end

# @param [Method, UnboundMethod] meth The method object.
Expand Down
18 changes: 18 additions & 0 deletions spec/pry-doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,25 @@ def self.my_method; end

lambda { Pry::MethodInfo.aliases(c.method(:my_method)) }.should.not.raise NameError
end
end

describe ".gem_root" do
it "should return the path to the gem" do
path = Pry::WrappedModule.new(Sample).source_location[0]

Pry::MethodInfo.gem_root(path).should ==
File.expand_path("gem_with_cext/gems", direc)
end

it "should not be fooled by a parent 'lib' or 'ext' dir" do
path = "/foo/.rbenv/versions/1.9.3-p429/lib/ruby/gems/"\
"1.9.1/gems/activesupport-4.0.2/lib/active_support/"\
"core_ext/kernel/reporting.rb"

Pry::MethodInfo.gem_root(path).should ==
"/foo/.rbenv/versions/1.9.3-p429/lib/ruby/"\
"gems/1.9.1/gems/activesupport-4.0.2"
end
end

if Pry::Helpers::BaseHelpers.mri_18?
Expand Down

0 comments on commit 7e1682c

Please sign in to comment.