From 254670b3bc1143e6a71ea203dae8c31cf2908730 Mon Sep 17 00:00:00 2001 From: kou Date: Fri, 25 Nov 2005 03:54:29 +0000 Subject: * lib/rss/rss.rb: added backward compatibility codes. * lib/rss/parser.rb: ditto. * test/rss/test_parser.rb: ditto. * test/rss/test_2.0.rb: ditto. * test/rss/test_content.rb: use #__send__ instead of #funcall for no private method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ lib/rss/parser.rb | 16 ++++++++++++++-- lib/rss/rss.rb | 8 ++++++++ test/rss/test_2.0.rb | 8 ++++---- test/rss/test_content.rb | 6 +++--- test/rss/test_parser.rb | 12 +++++++++++- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 001ccf18a8..a43dcc3d55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Nov 25 12:52:57 2005 Kouhei Sutou + + * lib/rss/rss.rb: added backward compatibility codes. + * lib/rss/parser.rb: ditto. + * test/rss/test_parser.rb: ditto. + * test/rss/test_2.0.rb: ditto. + + * test/rss/test_content.rb: use #__send__ instead of #funcall for + no private method. + Fri Nov 25 12:39:56 2005 Kouhei Sutou * lib/rss/rss.rb: improved type conversion. diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index 5308211b9d..e63e06e20d 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -1,5 +1,17 @@ require "forwardable" -require "open-uri" +begin + require "open-uri" +rescue LoadError + require "uri" +end +unless Kernel.methods.include?("URI") + module Kernel + def URI(uri_str) # :doc: + URI.parse(uri_str) + end + module_function :URI + end +end require "rss/rss" @@ -414,7 +426,7 @@ module RSS end previous = @last_element - next_element = klass.__send__(:new, *args) + next_element = klass.new(*args) next_element.do_validate = @do_validate previous.funcall(:set_next_element, tag_name, next_element) @last_element = next_element diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index 589478665c..f424f16171 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -52,6 +52,14 @@ class Hash end end +module Kernel + unless methods.include?("funcall") + def funcall(*args, &block) + __send__(*args, &block) + end + end +end + require "English" require "rss/utils" require "rss/converter" diff --git a/test/rss/test_2.0.rb b/test/rss/test_2.0.rb index 5e2e6bd851..2027e5344a 100644 --- a/test/rss/test_2.0.rb +++ b/test/rss/test_2.0.rb @@ -145,7 +145,7 @@ module RSS actual = {} cloud_elem.attributes.each do |name, value| value = value.to_i if name == "port" - actual[name.to_sym] = value + actual[name.intern] = value end assert_equal(cloud_params, actual) end @@ -313,7 +313,7 @@ module RSS actual = {} enclosure_elem.attributes.each do |name, value| value = value.to_i if name == "length" - actual[name.to_sym] = value + actual[name.intern] = value end assert_equal(enclosure_params, actual) end @@ -348,7 +348,7 @@ module RSS actual[:content] = guid_elem.text if guid_elem.text guid_elem.attributes.each do |name, value| value = value == "true" if name == "isPermaLink" - actual[name.to_sym] = value + actual[name.intern] = value end assert_equal(guid_params, actual) end @@ -369,7 +369,7 @@ module RSS actual = {} actual[:content] = source_elem.text source_elem.attributes.each do |name, value| - actual[name.to_sym] = value + actual[name.intern] = value end assert_equal(source_params, actual) end diff --git a/test/rss/test_content.rb b/test/rss/test_content.rb index b0ecbd4cf3..0622625e26 100644 --- a/test/rss/test_content.rb +++ b/test/rss/test_content.rb @@ -61,9 +61,9 @@ EOR @elems.each do |name, value| @parents.each do |parent| meth = "#{RSS::CONTENT_PREFIX}_#{name}" - assert_equal(value, @rss.__send__(parent).funcall(meth)) - @rss.__send__(parent).funcall("#{meth}=", new_value[name].to_s) - assert_equal(new_value[name], @rss.__send__(parent).funcall(meth)) + assert_equal(value, @rss.__send__(parent).__send__(meth)) + @rss.__send__(parent).__send__("#{meth}=", new_value[name].to_s) + assert_equal(new_value[name], @rss.__send__(parent).__send__(meth)) end end diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb index d6de0699a0..f410b1b4f0 100644 --- a/test/rss/test_parser.rb +++ b/test/rss/test_parser.rb @@ -1,4 +1,14 @@ -require "fileutils" +begin + require "fileutils" +rescue LoadError + module FileUtils + module_function + def rm_f(target) + File.unlink(target) + rescue Errno::ENOENT + end + end +end require "rss-testcase" -- cgit v1.2.3