ruby-changes:9107
From: kou <ko1@a...>
Date: Thu, 11 Dec 2008 21:08:42 +0900 (JST)
Subject: [ruby-changes:9107] Ruby:r20644 (ruby_1_8): * lib/rss/maker.rb, lib/rss/maker/0.9.rb, lib/rss/maker/base.rb:
kou 2008-12-11 21:08:20 +0900 (Thu, 11 Dec 2008) New Revision: 20644 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20644 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: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/rss/maker/0.9.rb branches/ruby_1_8/lib/rss/maker/base.rb branches/ruby_1_8/lib/rss/maker.rb branches/ruby_1_8/test/rss/test_maker_0.9.rb branches/ruby_1_8/test/rss/test_maker_1.0.rb branches/ruby_1_8/test/rss/test_maker_2.0.rb branches/ruby_1_8/test/rss/test_maker_atom_entry.rb branches/ruby_1_8/test/rss/test_maker_atom_feed.rb Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 20643) +++ ruby_1_8/ChangeLog (revision 20644) @@ -1,3 +1,10 @@ +Thu Dec 11 21:07:56 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:38:26 2008 Akinori MUSHA <knu@i...> * test/ruby/test_enumerator.rb: Add tests for the recently added Index: ruby_1_8/lib/rss/maker/0.9.rb =================================================================== --- ruby_1_8/lib/rss/maker/0.9.rb (revision 20643) +++ ruby_1_8/lib/rss/maker/0.9.rb (revision 20644) @@ -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: ruby_1_8/lib/rss/maker/base.rb =================================================================== --- ruby_1_8/lib/rss/maker/base.rb (revision 20643) +++ ruby_1_8/lib/rss/maker/base.rb (revision 20644) @@ -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: ruby_1_8/lib/rss/maker.rb =================================================================== --- ruby_1_8/lib/rss/maker.rb (revision 20643) +++ ruby_1_8/lib/rss/maker.rb (revision 20644) @@ -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: ruby_1_8/test/rss/test_maker_2.0.rb =================================================================== --- ruby_1_8/test/rss/test_maker_2.0.rb (revision 20643) +++ ruby_1_8/test/rss/test_maker_2.0.rb (revision 20644) @@ -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: ruby_1_8/test/rss/test_maker_atom_entry.rb =================================================================== --- ruby_1_8/test/rss/test_maker_atom_entry.rb (revision 20643) +++ ruby_1_8/test/rss/test_maker_atom_entry.rb (revision 20644) @@ -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: ruby_1_8/test/rss/test_maker_atom_feed.rb =================================================================== --- ruby_1_8/test/rss/test_maker_atom_feed.rb (revision 20643) +++ ruby_1_8/test/rss/test_maker_atom_feed.rb (revision 20644) @@ -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: ruby_1_8/test/rss/test_maker_1.0.rb =================================================================== --- ruby_1_8/test/rss/test_maker_1.0.rb (revision 20643) +++ ruby_1_8/test/rss/test_maker_1.0.rb (revision 20644) @@ -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: ruby_1_8/test/rss/test_maker_0.9.rb =================================================================== --- ruby_1_8/test/rss/test_maker_0.9.rb (revision 20643) +++ ruby_1_8/test/rss/test_maker_0.9.rb (revision 20644) @@ -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/