[前][次][番号順一覧][スレッド一覧]

ruby-changes:6161

From: kou <ko1@a...>
Date: Sun, 29 Jun 2008 17:43:01 +0900 (JST)
Subject: [ruby-changes:6161] Ruby:r17673 (trunk): * lib/rss/maker/base.rb (RSS::Maker::RSSBase#to_feed): raise

kou	2008-06-29 17:42:46 +0900 (Sun, 29 Jun 2008)

  New Revision: 17673

  Modified files:
    trunk/ChangeLog
    trunk/lib/rss/maker/base.rb
    trunk/test/rss/rss-assertions.rb

  Log:
    * lib/rss/maker/base.rb (RSS::Maker::RSSBase#to_feed): raise
      exception not return nil if RSS::Maker.make can't get required information.
    * test/rss/rss-assertions.rb: follow the above change.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rss/rss-assertions.rb?r1=17673&r2=17672&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=17673&r2=17672&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rss/maker/base.rb?r1=17673&r2=17672&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17672)
+++ ChangeLog	(revision 17673)
@@ -1,3 +1,10 @@
+Sun Jun 29 17:41:42 2008  Kouhei Sutou  <kou@c...>
+
+	* lib/rss/maker/base.rb (RSS::Maker::RSSBase#to_feed): raise
+	exception not return nil if RSS::Maker.make can't get required
+	information.
+	* test/rss/rss-assertions.rb: follow the above change.
+
 Sun Jun 29 17:37:23 2008  Kouhei Sutou  <kou@c...>
 
 	* lib/rss/maker/base.rb (RSS::Maker::RSSBase#make): require block.
Index: lib/rss/maker/base.rb
===================================================================
--- lib/rss/maker/base.rb	(revision 17672)
+++ lib/rss/maker/base.rb	(revision 17673)
@@ -420,11 +420,8 @@
         setup_xml_stylesheets(feed)
         setup_elements(feed)
         setup_other_elements(feed)
-        if feed.valid?
-          feed
-        else
-          nil
-        end
+        feed.validate
+        feed
       end
       
       private
Index: test/rss/rss-assertions.rb
===================================================================
--- test/rss/rss-assertions.rb	(revision 17672)
+++ test/rss/rss-assertions.rb	(revision 17673)
@@ -1272,22 +1272,32 @@
                                     invalid_feed_checker=nil)
       _wrap_assertion do
         elements = []
-        invalid_feed = false
-        feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
-          yield maker
-          targets = chain_reader(maker, maker_readers)
-          targets.each do |target|
-            element = maker_extractor.call(target)
-            elements << element if element
+        invalid_feed_exception = nil
+        feed = nil
+        begin
+          feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+            yield maker
+            targets = chain_reader(maker, maker_readers)
+            targets.each do |target|
+              element = maker_extractor.call(target)
+              elements << element if element
+            end
+            if invalid_feed_checker
+              invalid_feed_exception = invalid_feed_checker.call(targets)
+            end
           end
-          if invalid_feed_checker
-            invalid_feed = invalid_feed_checker.call(targets)
+        rescue RSS::Error
+          if invalid_feed_exception.is_a?(RSS::TooMuchTagError)
+            assert_too_much_tag(invalid_feed_exception.tag,
+                                invalid_feed_exception.parent) do
+              raise
+            end
+          else
+            raise
           end
         end
 
-        if invalid_feed
-          assert_nil(feed)
-        else
+        if invalid_feed_exception.nil?
           actual_elements = chain_reader(feed, feed_readers) || []
           actual_elements = actual_elements.collect do |target|
             feed_extractor.call(target)
@@ -1542,18 +1552,24 @@
           :length => target.length,
         }
       end
+
+      if feed_readers.first == "entries"
+        parent = "entry"
+      else
+        parent = feed_type
+      end
       invalid_feed_checker = Proc.new do |targets|
         infos = {}
-        invalid = false
+        invalid_exception = nil
         targets.each do |target|
           key = [target.hreflang, target.type]
           if infos.has_key?(key)
-            invalid = true
+            invalid_exception = RSS::TooMuchTagError.new("link", parent)
             break
           end
           infos[key] = true if target.rel.nil? or target.rel == "alternate"
         end
-        invalid
+        invalid_exception
       end
       invalid_feed_checker = nil if allow_duplication
       _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]