ruby-changes:9106
From: kou <ko1@a...>
Date: Thu, 11 Dec 2008 21:06:49 +0900 (JST)
Subject: [ruby-changes:9106] Ruby:r20643 (trunk): * lib/rss/maker.rb, lib/rss/maker/0.9.rb, lib/rss/maker/base.rb:
kou 2008-12-11 21:06:26 +0900 (Thu, 11 Dec 2008) New Revision: 20643 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20643 Log: * lib/rss/maker.rb, lib/rss/maker/0.9.rb, lib/rss/maker/base.rb: RSS::Maker.[] returns a maker class corresponds to passed version. * test/rss/test_maker_*.rb: add tests for RSS::Maker.[]. Modified files: trunk/ChangeLog trunk/lib/rss/maker/0.9.rb trunk/lib/rss/maker/base.rb trunk/lib/rss/maker.rb trunk/test/rss/test_maker_0.9.rb trunk/test/rss/test_maker_1.0.rb trunk/test/rss/test_maker_2.0.rb trunk/test/rss/test_maker_atom_entry.rb trunk/test/rss/test_maker_atom_feed.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 20642) +++ ChangeLog (revision 20643) @@ -1,3 +1,10 @@ +Thu Dec 11 21:04:04 2008 Kouhei Sutou <kou@c...> + + * lib/rss/maker.rb, lib/rss/maker/0.9.rb, lib/rss/maker/base.rb: + RSS::Maker.[] returns a maker class corresponds to passed version. + + * test/rss/test_maker_*.rb: add tests for RSS::Maker.[]. + Thu Dec 11 20:05:17 2008 Nobuyoshi Nakada <nobu@r...> * encoding.c (rb_enc_aliases_enc_i): skips default internal. Index: lib/rss/maker/0.9.rb =================================================================== --- lib/rss/maker/0.9.rb (revision 20642) +++ lib/rss/maker/0.9.rb (revision 20643) @@ -7,7 +7,7 @@ class RSS09 < RSSBase - def initialize(feed_version="0.92") + def initialize(feed_version) super @feed_type = "rss" end @@ -457,11 +457,51 @@ end end end - - add_maker("0.9", "0.92", RSS09) - add_maker("0.91", "0.91", RSS09) - add_maker("0.92", "0.92", RSS09) - add_maker("rss0.91", "0.91", RSS09) - add_maker("rss0.92", "0.92", RSS09) + + class RSS091 < RSS09 + def initialize(feed_version="0.91") + super + end + + class Channel < RSS09::Channel + end + + class Items < RSS09::Items + class Item < RSS09::Items::Item + end + end + + class Image < RSS09::Image + end + + class Textinput < RSS09::Textinput + end + end + + class RSS092 < RSS09 + def initialize(feed_version="0.92") + super + end + + class Channel < RSS09::Channel + end + + class Items < RSS09::Items + class Item < RSS09::Items::Item + end + end + + class Image < RSS09::Image + end + + class Textinput < RSS09::Textinput + end + end + + add_maker("0.9", "0.92", RSS092) + add_maker("0.91", "0.91", RSS091) + add_maker("0.92", "0.92", RSS092) + add_maker("rss0.91", "0.91", RSS091) + add_maker("rss0.92", "0.92", RSS092) end end Index: lib/rss/maker/base.rb =================================================================== --- lib/rss/maker/base.rb (revision 20642) +++ lib/rss/maker/base.rb (revision 20643) @@ -374,8 +374,8 @@ class RSSBase < Base class << self - def make(version, &block) - new(version).make(&block) + def make(*args, &block) + new(*args).make(&block) end end @@ -384,7 +384,7 @@ add_need_initialize_variable(element) do |object| object.send("make_#{element}") end - module_eval(<<-EOC, __FILE__, __LINE__) + module_eval(<<-EOC, __FILE__, __LINE__ + 1) private def setup_#{element}(feed) @#{element}.to_feed(feed) Index: lib/rss/maker.rb =================================================================== --- lib/rss/maker.rb (revision 20642) +++ lib/rss/maker.rb (revision 20643) @@ -6,14 +6,13 @@ class << self def make(version, &block) - maker_info = self[version] - maker_info[:maker].make(maker_info[:version], &block) + self[version].make(&block) end def [](version) maker_info = maker(version) raise UnsupportedMakerVersionError.new(version) if maker_info.nil? - maker_info + maker_info[:maker] end def add_maker(version, normalized_version, maker) Index: test/rss/test_maker_2.0.rb =================================================================== --- test/rss/test_maker_2.0.rb (revision 20642) +++ test/rss/test_maker_2.0.rb (revision 20643) @@ -4,6 +4,10 @@ module RSS class TestMaker20 < TestCase + def test_find_class + assert_equal(RSS::Maker::RSS20, RSS::Maker["2.0"]) + assert_equal(RSS::Maker::RSS20, RSS::Maker["rss2.0"]) + end def test_rss assert_raise(LocalJumpError) do Index: test/rss/test_maker_atom_entry.rb =================================================================== --- test/rss/test_maker_atom_entry.rb (revision 20642) +++ test/rss/test_maker_atom_entry.rb (revision 20643) @@ -4,6 +4,11 @@ module RSS class TestMakerAtomEntry < TestCase + def test_find_class + assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom:entry"]) + assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom1.0:entry"]) + end + def test_root_element entry = Maker.make("atom:entry") do |maker| setup_dummy_channel_atom(maker) Index: test/rss/test_maker_atom_feed.rb =================================================================== --- test/rss/test_maker_atom_feed.rb (revision 20642) +++ test/rss/test_maker_atom_feed.rb (revision 20643) @@ -4,6 +4,13 @@ module RSS class TestMakerAtomFeed < TestCase + def test_find_class + assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom"]) + assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom:feed"]) + assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0"]) + assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0:feed"]) + end + def test_root_element feed = Maker.make("atom") do |maker| setup_dummy_channel_atom(maker) Index: test/rss/test_maker_1.0.rb =================================================================== --- test/rss/test_maker_1.0.rb (revision 20642) +++ test/rss/test_maker_1.0.rb (revision 20643) @@ -4,6 +4,10 @@ module RSS class TestMaker10 < TestCase + def test_find_class + assert_equal(RSS::Maker::RSS10, RSS::Maker["1.0"]) + assert_equal(RSS::Maker::RSS10, RSS::Maker["rss1.0"]) + end def test_rdf assert_raise(LocalJumpError) do Index: test/rss/test_maker_0.9.rb =================================================================== --- test/rss/test_maker_0.9.rb (revision 20642) +++ test/rss/test_maker_0.9.rb (revision 20643) @@ -4,6 +4,13 @@ module RSS class TestMaker09 < TestCase + def test_find_class + assert_equal(RSS::Maker::RSS091, RSS::Maker["0.91"]) + assert_equal(RSS::Maker::RSS091, RSS::Maker["rss0.91"]) + assert_equal(RSS::Maker::RSS092, RSS::Maker["0.9"]) + assert_equal(RSS::Maker::RSS092, RSS::Maker["0.92"]) + assert_equal(RSS::Maker::RSS092, RSS::Maker["rss0.92"]) + end def test_rss assert_raise(LocalJumpError) do -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/