Permalink
Browse files

Added to_s on Pathname to support Ruby 1.9

  • Loading branch information...
1 parent 0a59617 commit 9a765891df6c28d8a48086aa3bf2e2d4692be26b @cjheath committed Sep 13, 2009
Showing with 61 additions and 7 deletions.
  1. +16 −0 History.txt
  2. +1 −1 Rakefile
  3. +2 −1 config/hoe.rb
  4. +18 −3 lib/polyglot.rb
  5. +1 −1 lib/polyglot/version.rb
  6. +22 −0 test/test_polyglot.rb
  7. +1 −1 website/index.html
View
@@ -1,3 +1,19 @@
+== 0.2.9 2009-09-13
+
+* 1 minor fix:
+ * Use to_s on Pathname to support Ruby 1.9
+
+== 0.2.8 2009-08-18
+
+* 1 minor fix:
+ * Previous fix for LoadErrors failed for cucumber.
+
+== 0.2.7 2009-08-17
+
+* 1 minor fix:
+ * Fix Polyglot catching LoadErrors not raised in Polyglot.find and re-raising the
+ wrong message.
+
== 0.2.6 2009-06-21
* 1 significant fix:
View
@@ -1,4 +1,4 @@
require 'config/requirements'
require 'config/hoe' # setup Hoe + all gem configuration
-Dir['tasks/**/*.rake'].each { |rake| load rake }
+Dir['tasks/**/*.rake'].each { |rake| load rake }
View
@@ -47,7 +47,8 @@ def extra_deps
# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)
-hoe = Hoe.new(GEM_NAME, VERS) do |p|
+hoe = Hoe.spec(GEM_NAME) do |p|
+ p.version = VERS
p.author = AUTHOR
p.description = DESCRIPTION
p.email = EMAIL
View
@@ -5,6 +5,15 @@ module Polyglot
@registrations ||= {} # Guard against reloading
@loaded ||= {}
+ class NestedLoadError < LoadError
+ def initialize le
+ @le = le
+ end
+ def reraise
+ raise @le
+ end
+ end
+
def self.register(extension, klass)
extension = [extension] unless Enumerable === extension
extension.each{|e|
@@ -18,7 +27,7 @@ def self.find(file, *options, &block)
(is_absolute ? [""] : $:).each{|lib|
base = is_absolute ? "" : lib+File::SEPARATOR
# In Windows, repeated SEPARATOR chars have a special meaning, avoid adding them
- matches = Dir[base+file+".{"+extensions+"}"]
+ matches = Dir[(base+file+".{"+extensions+"}").to_s]
# Revisit: Should we do more do if more than one candidate found?
$stderr.puts "Polyglot: found more than one candidate for #{file}: #{matches*", "}" if matches.size > 1
if path = matches[0]
@@ -34,8 +43,12 @@ def self.load(*a, &b)
begin
source_file, loader = Polyglot.find(file, *a[1..-1], &b)
if (loader)
- loader.load(source_file)
- @loaded[file] = true
+ begin
+ loader.load(source_file)
+ @loaded[file] = true
+ rescue LoadError => e
+ raise Polyglot::NestedLoadError.new(e)
+ end
else
msg = "Failed to load #{file} using extensions #{(@registrations.keys+["rb"]).sort*", "}"
if defined?(MissingSourceFile)
@@ -56,6 +69,8 @@ def require(*a, &b)
rescue LoadError => load_error
begin
Polyglot.load(*a, &b)
+ rescue Polyglot::NestedLoadError => e
+ e.reraise
rescue LoadError
# Raise the original exception, possibly a MissingSourceFile with a path
raise load_error
View
@@ -2,7 +2,7 @@ module Polyglot #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 2
- TINY = 6
+ TINY = 9
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
@@ -2,21 +2,43 @@
class TestPolyglot < Test::Unit::TestCase
TEST_FILE = 'test_file.stub'
+ TEST_REQUIRES_FILE = 'test_requires_file.eval'
class StubLoader
def self.load(*args); end
end
+ class EvalLoader
+ def self.load(file)
+ File.open(file) do |source_file|
+ source = source_file.read
+ eval source
+ end
+ end
+ end
def setup
Polyglot.register('stub', StubLoader)
File.open(TEST_FILE, 'w') { |f| f.puts "Test data" }
+ Polyglot.register('eval', EvalLoader)
+ File.open(TEST_REQUIRES_FILE, 'w') { |f| f.puts "require 'nonexistent_file'" }
end
def teardown
File.delete(TEST_FILE)
+ File.delete(TEST_REQUIRES_FILE)
end
def test_load_by_absolute_path
full_path = File.expand_path(TEST_FILE.sub(/.stub$/, ''))
assert_nothing_raised { require full_path }
end
+
+ def test_load_error
+ exception = assert_raise(LoadError) { require "nonexistent_file" }
+ assert_match(/nonexistent_file/, exception.message)
+ end
+
+ def test_load_error_inside_poly_file
+ exception = assert_raise(LoadError) { require TEST_REQUIRES_FILE.sub(/.eval$/, '') }
+ assert_match(/nonexistent_file/, exception.message)
+ end
end
View
@@ -33,7 +33,7 @@
<h1>polyglot</h1>
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/polyglot"; return false'>
<p>Get Version</p>
- <a href="http://rubyforge.org/projects/polyglot" class="numbers">0.2.5</a>
+ <a href="http://rubyforge.org/projects/polyglot" class="numbers">0.2.8</a>
</div>
<h2>Poly =&gt; many, glot =&gt; languages</h2>
<h2>What</h2>

0 comments on commit 9a76589

Please sign in to comment.