Skip to content

Commit

Permalink
Add GemFile to read .gem files
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jun 2, 2011
1 parent d4e3d91 commit d3f2044
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
26 changes: 26 additions & 0 deletions lib/rubygems_fp.rb
@@ -1,3 +1,6 @@
require "rubygems"
require "rubygems/package"

class RubyGemsFP
VERSION = '1.0.0'

Expand All @@ -18,4 +21,27 @@ def file_exists?(path)
File.exists? File.join(gem_dir, path)
end
end

class GemFile
def initialize(io)
@io = io
end

def self.from_path(path)
new File.open(path)
end

def read_file(path)
Gem::Package.open(@io) do |pkg|
pkg.each do |e|
if e.full_name == path
return e.read
end
end
end

nil
end

end
end
Binary file added test/test-1.0.gem
Binary file not shown.
19 changes: 19 additions & 0 deletions test/test_gemfile.rb
@@ -0,0 +1,19 @@
require "rubygems"
require "rubygems_fp"
require "test/unit"

class TestRubyGemsFPGemFile < Test::Unit::TestCase
def setup
@path = File.expand_path("../test-1.0.gem", __FILE__)
end

def test_read_file
gf = RubyGemsFP::GemFile.from_path @path
assert_equal "This is a file in the test gem\n", gf.read_file("test-file")
end

def test_read_file_nonexistant
gf = RubyGemsFP::GemFile.from_path @path
assert_equal nil, gf.read_file("not_there")
end
end
2 changes: 1 addition & 1 deletion test/test_rubygems_fp.rb
Expand Up @@ -73,7 +73,7 @@ def quick_gem(name, version='2')
return spec
end

def test_sanity
def test_gem_dir
a = quick_gem "a", "2"

s = RubyGemsFP::Specification.new(a)
Expand Down

0 comments on commit d3f2044

Please sign in to comment.