1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rss/rss.rb:

- cleanup validation mechanism. Now, #XXX_validation is
    needless.
  - changed internal variable name RSS::Element::MODEL to
    RSS::Element::MODELS.
  - RSS::Element.install_model requires uri.

* lib/rss/0.9.rb: followed new validation API.
* lib/rss/1.0.rb: ditto.
* lib/rss/2.0.rb: ditto.
* lib/rss/content.rb: ditto.
* lib/rss/dublincore.rb: ditto.
* lib/rss/image.rb: ditto.
* lib/rss/syndication.rb: ditto.
* lib/rss/taxonomy.rb: ditto.
* lib/rss/trackback.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2006-06-19 16:12:45 +00:00
parent eb41c8d2e3
commit b60b8361fd
11 changed files with 109 additions and 198 deletions

View file

@ -1,3 +1,22 @@
Tue Jun 20 01:06:57 2006 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/rss.rb:
- cleanup validation mechanism. Now, #XXX_validation is
needless.
- changed internal variable name RSS::Element::MODEL to
RSS::Element::MODELS.
- RSS::Element.install_model requires uri.
* lib/rss/0.9.rb: followed new validation API.
* lib/rss/1.0.rb: ditto.
* lib/rss/2.0.rb: ditto.
* lib/rss/content.rb: ditto.
* lib/rss/dublincore.rb: ditto.
* lib/rss/image.rb: ditto.
* lib/rss/syndication.rb: ditto.
* lib/rss/taxonomy.rb: ditto.
* lib/rss/trackback.rb: ditto.
Mon Jun 19 23:40:59 2006 NARUSE, Yui <naruse@ruby-lang.org> Mon Jun 19 23:40:59 2006 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/lib/kconv.rb: remove default -m0 and fix document. * ext/nkf/lib/kconv.rb: remove default -m0 and fix document.

View file

@ -22,7 +22,7 @@ module RSS
[ [
["channel", nil], ["channel", nil],
].each do |tag, occurs| ].each do |tag, occurs|
install_model(tag, occurs) install_model(tag, "", occurs)
end end
%w(channel).each do |name| %w(channel).each do |name|
@ -109,7 +109,7 @@ module RSS
["textInput", "?", :have_child], ["textInput", "?", :have_child],
].each do |name, occurs, type, *args| ].each do |name, occurs, type, *args|
__send__("install_#{type}_element", name, *args) __send__("install_#{type}_element", name, *args)
install_model(name, occurs) install_model(name, "", occurs)
end end
alias date pubDate alias date pubDate
alias date= pubDate= alias date= pubDate=
@ -179,7 +179,7 @@ module RSS
["day", "*"] ["day", "*"]
].each do |name, occurs| ].each do |name, occurs|
install_have_children_element(name) install_have_children_element(name)
install_model(name, occurs) install_model(name, "", occurs)
end end
private private
@ -218,7 +218,7 @@ module RSS
["hour", "*"] ["hour", "*"]
].each do |name, occurs| ].each do |name, occurs|
install_have_children_element(name) install_have_children_element(name)
install_model(name, occurs) install_model(name, "", occurs)
end end
private private
@ -255,7 +255,7 @@ module RSS
%w(url title link).each do |name| %w(url title link).each do |name|
install_text_element(name) install_text_element(name)
install_model(name, nil) install_model(name, "", nil)
end end
[ [
["width", :integer], ["width", :integer],
@ -263,7 +263,7 @@ module RSS
["description"], ["description"],
].each do |name, type| ].each do |name, type|
install_text_element(name, type) install_text_element(name, type)
install_model(name, "?") install_model(name, "", "?")
end end
def initialize(*args) def initialize(*args)
@ -335,7 +335,7 @@ module RSS
["enclosure", '?', :have_child], ["enclosure", '?', :have_child],
].each do |tag, occurs, type, *args| ].each do |tag, occurs, type, *args|
__send__("install_#{type}_element", tag, *args) __send__("install_#{type}_element", tag, *args)
install_model(tag, occurs) install_model(tag, "", occurs)
end end
private private
@ -486,7 +486,7 @@ module RSS
%w(title description name link).each do |name| %w(title description name link).each do |name|
install_text_element(name) install_text_element(name)
install_model(name, nil) install_model(name, "", nil)
end end
def initialize(*args) def initialize(*args)

View file

@ -41,7 +41,7 @@ module RSS
["item", "+"], ["item", "+"],
["textinput", "?"], ["textinput", "?"],
].each do |tag, occurs| ].each do |tag, occurs|
install_model(tag, occurs) install_model(tag, ::RSS::URI, occurs)
if occurs == "+" if occurs == "+"
install_have_children_element(tag) install_have_children_element(tag)
else else
@ -121,7 +121,7 @@ module RSS
@tag_name = 'Seq' @tag_name = 'Seq'
install_have_children_element("li") install_have_children_element("li")
install_model("li", URI, "*")
install_must_call_validator('rdf', ::RSS::RDF::URI) install_must_call_validator('rdf', ::RSS::RDF::URI)
def initialize(*args) def initialize(*args)
@ -147,10 +147,6 @@ module RSS
def children def children
@li @li
end end
def rdf_validate(ignore_unknown_element, tags, uri)
_validate(ignore_unknown_element, tags, uri, [["li", '*']])
end
def _tags def _tags
rv = [] rv = []
@ -176,7 +172,7 @@ module RSS
@tag_name = 'Bag' @tag_name = 'Bag'
install_have_children_element("li") install_have_children_element("li")
install_model("li", URI, "*")
install_must_call_validator('rdf', ::RSS::RDF::URI) install_must_call_validator('rdf', ::RSS::RDF::URI)
def initialize(*args) def initialize(*args)
@ -202,10 +198,6 @@ module RSS
def children def children
@li @li
end end
def rdf_validate(ignore_unknown_element, tags, uri)
_validate(ignore_unknown_element, tags, uri, [["li", '*']])
end
def _tags def _tags
rv = [] rv = []
@ -251,7 +243,7 @@ module RSS
['items', nil], ['items', nil],
['textinput', '?'], ['textinput', '?'],
].each do |tag, occurs| ].each do |tag, occurs|
install_model(tag, occurs) install_model(tag, ::RSS::URI, occurs)
end end
def initialize(*args) def initialize(*args)
@ -362,8 +354,8 @@ module RSS
end end
install_have_child_element("Seq") install_have_child_element("Seq")
install_model("Seq", URI, nil)
install_must_call_validator('rdf', ::RSS::RDF::URI) install_must_call_validator('rdf', URI)
def initialize(*args) def initialize(*args)
if Utils.element_initialize_arguments?(args) if Utils.element_initialize_arguments?(args)
@ -395,10 +387,6 @@ module RSS
rv << [URI, 'Seq'] unless @Seq.nil? rv << [URI, 'Seq'] unless @Seq.nil?
rv rv
end end
def rdf_validate(ignore_unknown_element, tags, uri)
_validate(ignore_unknown_element, tags, uri, [["Seq", nil]])
end
end end
end end
@ -430,7 +418,7 @@ module RSS
['url', nil], ['url', nil],
['link', nil], ['link', nil],
].each do |tag, occurs| ].each do |tag, occurs|
install_model(tag, occurs) install_model(tag, ::RSS::URI, occurs)
end end
def initialize(*args) def initialize(*args)
@ -487,7 +475,7 @@ module RSS
["link", nil], ["link", nil],
["description", "?"], ["description", "?"],
].each do |tag, occurs| ].each do |tag, occurs|
install_model(tag, occurs) install_model(tag, ::RSS::URI, occurs)
end end
def initialize(*args) def initialize(*args)
@ -548,7 +536,7 @@ module RSS
["name", nil], ["name", nil],
["link", nil], ["link", nil],
].each do |tag, occurs| ].each do |tag, occurs|
install_model(tag, occurs) install_model(tag, ::RSS::URI, occurs)
end end
def initialize(*args) def initialize(*args)

View file

@ -11,21 +11,21 @@ module RSS
["ttl", :integer], ["ttl", :integer],
].each do |name, type| ].each do |name, type|
install_text_element(name, type) install_text_element(name, type)
install_model(name, '?') install_model(name, "", '?')
end end
[ [
%w(category categories), %w(category categories),
].each do |name, plural_name| ].each do |name, plural_name|
install_have_children_element(name, plural_name) install_have_children_element(name, plural_name)
install_model(name, '*') install_model(name, "", '*')
end end
[ [
["image", "?"], ["image", "?"],
["language", "?"], ["language", "?"],
].each do |name, occurs| ].each do |name, occurs|
install_model(name, occurs) install_model(name, "", occurs)
end end
private private
@ -58,14 +58,14 @@ module RSS
["author", "?"], ["author", "?"],
].each do |name, occurs| ].each do |name, occurs|
install_text_element(name) install_text_element(name)
install_model(name, occurs) install_model(name, "", occurs)
end end
[ [
["pubDate", '?'], ["pubDate", '?'],
].each do |name, occurs| ].each do |name, occurs|
install_date_element(name, 'rfc822') install_date_element(name, 'rfc822')
install_model(name, occurs) install_model(name, "", occurs)
end end
alias date pubDate alias date pubDate
alias date= pubDate= alias date= pubDate=
@ -74,7 +74,7 @@ module RSS
["guid", '?'], ["guid", '?'],
].each do |name, occurs| ].each do |name, occurs|
install_have_child_element(name) install_have_child_element(name)
install_model(name, occurs) install_model(name, "", occurs)
end end
private private

View file

@ -15,30 +15,13 @@ module RSS
def self.append_features(klass) def self.append_features(klass)
super super
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(encoded).each do |name|
install_text_element("\#{CONTENT_PREFIX}_\#{name}")
end
EOC
end
def content_validate(ignore_unknown_element, tags, uri) klass.install_must_call_validator(CONTENT_PREFIX, CONTENT_URI)
counter = {} %w(encoded).each do |name|
ELEMENTS.each do |name| klass.install_text_element("#{CONTENT_PREFIX}_#{name}")
counter[name] = 0 klass.install_model(name, CONTENT_URI, "?")
end
tags.each do |tag|
key = "#{CONTENT_PREFIX}_#{tag}"
if !ignore_unknown_element and !counter.has_key?(key)
raise UnknownTagError.new(tag, CONTENT_URI)
end
counter[key] += 1
raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
end end
end end
end end
class RDF class RDF

View file

@ -17,10 +17,10 @@ module RSS
full_name = "#{DC_PREFIX}_#{name}" full_name = "#{DC_PREFIX}_#{name}"
full_plural_name = "#{DC_PREFIX}_#{plural}" full_plural_name = "#{DC_PREFIX}_#{plural}"
klass_name = "DublinCore#{Utils.to_class_name(name)}" klass_name = "DublinCore#{Utils.to_class_name(name)}"
klass.install_must_call_validator(DC_PREFIX, DC_URI)
klass.install_model(name, DC_URI, "*")
klass.install_have_children_element(full_name, full_plural_name)
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0)) klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
install_have_children_element(#{full_name.dump},
#{full_plural_name.dump})
remove_method :#{full_name} remove_method :#{full_name}
remove_method :#{full_name}= remove_method :#{full_name}=
remove_method :set_#{full_name} remove_method :set_#{full_name}
@ -133,17 +133,6 @@ module RSS
end end
EOC EOC
end end
def dc_validate(ignore_unknown_element, tags, uri)
tags.each do |tag|
key = "#{DC_PREFIX}_#{tag}"
if !ignore_unknown_element and
!DublinCoreModel::ELEMENTS.include?(key)
raise UnknownTagError.new(tag, DC_URI)
end
end
end
end end
# For backward compatibility # For backward compatibility

View file

@ -34,12 +34,10 @@ module RSS
super super
klass.install_have_child_element("#{IMAGE_PREFIX}_item") klass.install_have_child_element("#{IMAGE_PREFIX}_item")
klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
klass.install_model("item", IMAGE_URI, "?")
end end
def image_validate(ignore_unknown_element, tags, uri)
validate_one_tag_name(ignore_unknown_element, "item", tags)
end
class ImageItem < Element class ImageItem < Element
include RSS10 include RSS10
include DublinCoreModel include DublinCoreModel
@ -56,6 +54,8 @@ module RSS
end end
end end
install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
[ [
["about", ::RSS::RDF::URI, true], ["about", ::RSS::RDF::URI, true],
["resource", ::RSS::RDF::URI, false], ["resource", ::RSS::RDF::URI, false],
@ -120,13 +120,11 @@ module RSS
unless klass.class == Module unless klass.class == Module
klass.install_have_child_element("#{IMAGE_PREFIX}_favicon") klass.install_have_child_element("#{IMAGE_PREFIX}_favicon")
klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
klass.install_model("favicon", IMAGE_URI, "?")
end end
end end
def image_validate(ignore_unknown_element, tags, uri)
validate_one_tag_name(ignore_unknown_element, "favicon", tags)
end
class ImageFavicon < Element class ImageFavicon < Element
include RSS10 include RSS10
include DublinCoreModel include DublinCoreModel

View file

@ -391,7 +391,7 @@ EOC
INDENT = " " INDENT = " "
MUST_CALL_VALIDATORS = {} MUST_CALL_VALIDATORS = {}
MODEL = [] MODELS = []
GET_ATTRIBUTES = [] GET_ATTRIBUTES = []
HAVE_CHILDREN_ELEMENTS = [] HAVE_CHILDREN_ELEMENTS = []
TO_ELEMENT_METHODS = [] TO_ELEMENT_METHODS = []
@ -403,8 +403,8 @@ EOC
def must_call_validators def must_call_validators
MUST_CALL_VALIDATORS MUST_CALL_VALIDATORS
end end
def model def models
MODEL MODELS
end end
def get_attributes def get_attributes
GET_ATTRIBUTES GET_ATTRIBUTES
@ -425,7 +425,7 @@ EOC
def inherited(klass) def inherited(klass)
klass.const_set("MUST_CALL_VALIDATORS", {}) klass.const_set("MUST_CALL_VALIDATORS", {})
klass.const_set("MODEL", []) klass.const_set("MODELS", [])
klass.const_set("GET_ATTRIBUTES", []) klass.const_set("GET_ATTRIBUTES", [])
klass.const_set("HAVE_CHILDREN_ELEMENTS", []) klass.const_set("HAVE_CHILDREN_ELEMENTS", [])
klass.const_set("TO_ELEMENT_METHODS", []) klass.const_set("TO_ELEMENT_METHODS", [])
@ -442,8 +442,8 @@ EOC
def self.must_call_validators def self.must_call_validators
super.merge(MUST_CALL_VALIDATORS) super.merge(MUST_CALL_VALIDATORS)
end end
def self.model def self.models
MODEL + super MODELS + super
end end
def self.get_attributes def self.get_attributes
GET_ATTRIBUTES + super GET_ATTRIBUTES + super
@ -466,11 +466,11 @@ EOC
MUST_CALL_VALIDATORS[uri] = prefix MUST_CALL_VALIDATORS[uri] = prefix
end end
def self.install_model(tag, occurs=nil) def self.install_model(tag, uri, occurs=nil)
if m = MODEL.find {|t, o| t == tag} if m = MODELS.find {|t, u, o| t == tag and u == uri}
m[1] = occurs m[2] = occurs
else else
MODEL << [tag, occurs] MODELS << [tag, uri, occurs]
end end
end end
@ -783,16 +783,12 @@ EOC
must_call_validators = self.class.must_call_validators must_call_validators = self.class.must_call_validators
tags = tag_filter(tags.dup) tags = tag_filter(tags.dup)
p tags if DEBUG p tags if DEBUG
self.class::NSPOOL.each do |prefix, uri|
if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
meth = "#{prefix}_validate"
if respond_to?(meth, true)
__send__(meth, ignore_unknown_element, tags[uri], uri)
end
end
end
must_call_validators.each do |uri, prefix| must_call_validators.each do |uri, prefix|
__send__("#{prefix}_validate", ignore_unknown_element, tags[uri], uri) _validate(ignore_unknown_element, tags[uri], uri)
meth = "#{prefix}_validate"
if respond_to?(meth, true)
__send__(meth, ignore_unknown_element, tags[uri], uri)
end
end end
end end
@ -804,23 +800,25 @@ EOC
end end
end end
def _validate(ignore_unknown_element, tags, uri, model=self.class.model) def _validate(ignore_unknown_element, tags, uri, models=self.class.models)
count = 1 count = 1
do_redo = false do_redo = false
not_shift = false not_shift = false
tag = nil tag = nil
element_names = model.collect {|elem| elem[0]} models = models.find_all {|model| model[1] == uri}
element_names = models.collect {|model| model[0]}
if tags if tags
tags_size = tags.size tags_size = tags.size
tags = tags.sort_by {|x| element_names.index(x) || tags_size} tags = tags.sort_by {|x| element_names.index(x) || tags_size}
end end
model.each_with_index do |elem, i| models.each_with_index do |model, i|
name, model_uri, occurs = model
if DEBUG if DEBUG
p "before" p "before"
p tags p tags
p elem p model
end end
if not_shift if not_shift
@ -834,41 +832,41 @@ EOC
p count p count
end end
case elem[1] case occurs
when '?' when '?'
if count > 2 if count > 2
raise TooMuchTagError.new(elem[0], tag_name) raise TooMuchTagError.new(name, tag_name)
else else
if elem[0] == tag if name == tag
do_redo = true do_redo = true
else else
not_shift = true not_shift = true
end end
end end
when '*' when '*'
if elem[0] == tag if name == tag
do_redo = true do_redo = true
else else
not_shift = true not_shift = true
end end
when '+' when '+'
if elem[0] == tag if name == tag
do_redo = true do_redo = true
else else
if count > 1 if count > 1
not_shift = true not_shift = true
else else
raise MissingTagError.new(elem[0], tag_name) raise MissingTagError.new(name, tag_name)
end end
end end
else else
if elem[0] == tag if name == tag
if model[i+1] and model[i+1][0] != elem[0] and if models[i+1] and models[i+1][0] != name and
tags and tags.first == elem[0] tags and tags.first == name
raise TooMuchTagError.new(elem[0], tag_name) raise TooMuchTagError.new(name, tag_name)
end end
else else
raise MissingTagError.new(elem[0], tag_name) raise MissingTagError.new(name, tag_name)
end end
end end

View file

@ -15,18 +15,21 @@ module RSS
def self.append_features(klass) def self.append_features(klass)
super super
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1)) klass.install_must_call_validator(SY_PREFIX, SY_URI)
klass.module_eval do
[ [
["updatePeriod"], ["updatePeriod"],
["updateFrequency", :positive_integer] ["updateFrequency", :positive_integer]
].each do |name, type| ].each do |name, type|
install_text_element("\#{SY_PREFIX}_\#{name}", type, install_text_element("#{SY_PREFIX}_#{name}", type,
"\#{SY_PREFIX}:\#{name}") "#{SY_PREFIX}:#{name}")
install_model(name, SY_URI, "?")
end end
%w(updateBase).each do |name| %w(updateBase).each do |name|
install_date_element("\#{SY_PREFIX}_\#{name}", 'w3cdtf', name) install_date_element("#{SY_PREFIX}_#{name}", 'w3cdtf', name)
install_model(name, SY_URI, "?")
end end
alias_method(:_sy_updatePeriod=, :sy_updatePeriod=) alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
@ -35,22 +38,6 @@ module RSS
validate_sy_updatePeriod(new_value) if @do_validate validate_sy_updatePeriod(new_value) if @do_validate
self._sy_updatePeriod = new_value self._sy_updatePeriod = new_value
end end
EOC
end
def sy_validate(ignore_unknown_element, tags, uri)
counter = {}
ELEMENTS.each do |name|
counter[name] = 0
end
tags.each do |tag|
key = "#{SY_PREFIX}_#{tag}"
if ignore_unknown_element and !counter.has_key?(key)
raise UnknownTagError.new(tag, SY_URI)
end
counter[key] += 1
raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
end end
end end

View file

@ -28,22 +28,10 @@ module RSS
def self.append_features(klass) def self.append_features(klass)
super super
var_name = "#{TAXO_PREFIX}_topics" klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
klass.install_have_child_element(var_name) %w(topics).each do |name|
end klass.install_have_child_element("#{TAXO_PREFIX}_#{name}")
klass.install_model(name, TAXO_URI, "?")
def taxo_validate(ignore_unknown_element, tags, uri)
found_topics = false
tags.each do |tag|
if tag == "topics"
if found_topics
raise TooMuchTagError.new(tag, tag_name)
else
found_topics = true
end
elsif !ignore_unknown_element
raise UnknownTagError.new(tag, TAXO_URI)
end
end end
end end
@ -65,8 +53,8 @@ module RSS
@tag_name = "topics" @tag_name = "topics"
install_have_child_element("Bag") install_have_child_element("Bag")
install_model("Bag", RDF::URI, nil)
install_must_call_validator('rdf', ::RSS::RDF::URI) install_must_call_validator('rdf', RDF::URI)
def initialize(*args) def initialize(*args)
if Utils.element_initialize_arguments?(args) if Utils.element_initialize_arguments?(args)
@ -103,13 +91,9 @@ module RSS
def _tags def _tags
rv = [] rv = []
rv << [::RSS::RDF::URI, 'Bag'] unless @Bag.nil? rv << [RDF::URI, 'Bag'] unless @Bag.nil?
rv rv
end end
def rdf_validate(ignore_unknown_element, tags, uri)
_validate(ignore_unknown_element, tags, uri, [["Bag", nil]])
end
end end
end end
@ -122,14 +106,6 @@ module RSS
klass.install_have_children_element(var_name) klass.install_have_children_element(var_name)
end end
def taxo_validate(ignore_unknown_element, tags, uri)
tags.each do |tag|
if !ignore_unknown_element and tag != "topic"
raise UnknownTagError.new(tag, TAXO_URI)
end
end
end
class TaxonomyTopic < Element class TaxonomyTopic < Element
include RSS10 include RSS10
@ -165,21 +141,6 @@ module RSS
tag_name_with_prefix(TAXO_PREFIX) tag_name_with_prefix(TAXO_PREFIX)
end end
def taxo_validate(ignore_unknown_element, tags, uri)
elements = %w(link topics)
counter = {}
tags.each do |tag|
if elements.include?(tag)
counter[tag] ||= 0
counter[tag] += 1
raise TooMuchTagError.new(tag, tag_name) if counter[tag] > 1
elsif !ignore_unknown_element
raise UnknownTagError.new(tag, TAXO_URI)
end
end
end
def maker_target(target) def maker_target(target)
target.new_taxo_topic target.new_taxo_topic
end end

View file

@ -12,29 +12,14 @@ module RSS
module TrackBackUtils module TrackBackUtils
private private
def trackback_validate(ignore_unknown_element, tags, uri) def trackback_validate(ignore_unknown_element, tags, uri)
counter = {} return if tags.nil?
%w(ping about).each do |name| if tags.find {|tag| tag == "about"} and
counter["#{TRACKBACK_PREFIX}_#{name}"] = 0 !tags.find {|tag| tag == "ping"}
end
tags.each do |tag|
key = "#{TRACKBACK_PREFIX}_#{tag}"
if !ignore_unknown_element and !counter.has_key?(key)
raise UnknownTagError.new(tag, TRACKBACK_URI)
end
counter[key] += 1
if tag != "about" and counter[key] > 1
raise TooMuchTagError.new(tag, tag_name)
end
end
if counter["#{TRACKBACK_PREFIX}_ping"].zero? and
counter["#{TRACKBACK_PREFIX}_about"].nonzero?
raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name) raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
end end
end end
end end
module BaseTrackBackModel module BaseTrackBackModel
ELEMENTS = %w(ping about) ELEMENTS = %w(ping about)
@ -45,10 +30,12 @@ module RSS
unless klass.class == Module unless klass.class == Module
klass.module_eval {include TrackBackUtils} klass.module_eval {include TrackBackUtils}
klass.install_must_call_validator(TRACKBACK_PREFIX, TRACKBACK_URI)
%w(ping).each do |name| %w(ping).each do |name|
var_name = "#{TRACKBACK_PREFIX}_#{name}" var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = "TrackBack#{Utils.to_class_name(name)}" klass_name = "TrackBack#{Utils.to_class_name(name)}"
klass.install_have_child_element(var_name) klass.install_have_child_element(var_name)
klass.install_model(name, TRACKBACK_URI, "?")
klass.module_eval(<<-EOC, __FILE__, __LINE__) klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name} remove_method :#{var_name}
def #{var_name} def #{var_name}
@ -66,6 +53,7 @@ module RSS
var_name = "#{TRACKBACK_PREFIX}_#{name}" var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = "TrackBack#{Utils.to_class_name(name)}" klass_name = "TrackBack#{Utils.to_class_name(name)}"
klass.install_have_children_element(var_name) klass.install_have_children_element(var_name)
klass.install_model(name, TRACKBACK_URI, "*")
klass.module_eval(<<-EOC, __FILE__, __LINE__) klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name} remove_method :#{var_name}
def #{var_name}(*args) def #{var_name}(*args)