mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rss/rss.rb (RSS::VERSION): 0.1.2 -> 0.1.3.
* lib/rss/rss.rb: accept inheritance. [ruby-talk:126104] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c853ea40c3
commit
e1e5eda547
5 changed files with 114 additions and 50 deletions
|
@ -1,3 +1,9 @@
|
|||
Sat Jan 15 13:44:22 2005 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rss/rss.rb (RSS::VERSION): 0.1.2 -> 0.1.3.
|
||||
|
||||
* lib/rss/rss.rb: accept inheritance. [ruby-talk:126104]
|
||||
|
||||
Wed Jan 12 00:36:29 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* object.c (rb_class_superclass): superclass of singleton class also
|
||||
|
|
|
@ -21,17 +21,17 @@ module RSS
|
|||
|
||||
subclass.module_eval(<<-EOEOC, __FILE__, __LINE__)
|
||||
def self.other_elements
|
||||
const_get("OTHER_ELEMENTS") + super
|
||||
OTHER_ELEMENTS + super
|
||||
end
|
||||
|
||||
def self.need_initialize_variables
|
||||
const_get("NEED_INITIALIZE_VARIABLES") + super
|
||||
NEED_INITIALIZE_VARIABLES + super
|
||||
end
|
||||
EOEOC
|
||||
end
|
||||
|
||||
def self.add_other_element(variable_name)
|
||||
const_get("OTHER_ELEMENTS") << variable_name
|
||||
OTHER_ELEMENTS << variable_name
|
||||
end
|
||||
|
||||
def self.other_elements
|
||||
|
@ -39,7 +39,7 @@ module RSS
|
|||
end
|
||||
|
||||
def self.add_need_initialize_variable(variable_name, init_value="nil")
|
||||
const_get("NEED_INITIALIZE_VARIABLES") << [variable_name, init_value]
|
||||
NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
|
||||
end
|
||||
|
||||
def self.need_initialize_variables
|
||||
|
|
107
lib/rss/rss.rb
107
lib/rss/rss.rb
|
@ -58,7 +58,7 @@ require "rss/xml-stylesheet"
|
|||
|
||||
module RSS
|
||||
|
||||
VERSION = "0.1.2"
|
||||
VERSION = "0.1.3"
|
||||
|
||||
URI = "http://purl.org/rss/1.0/"
|
||||
|
||||
|
@ -355,93 +355,110 @@ EOC
|
|||
|
||||
INDENT = " "
|
||||
|
||||
MUST_CALL_VALIDATORS = {}
|
||||
MODEL = []
|
||||
GET_ATTRIBUTES = []
|
||||
HAVE_CHILDREN_ELEMENTS = []
|
||||
NEED_INITIALIZE_VARIABLES = []
|
||||
PLURAL_FORMS = {}
|
||||
|
||||
class << self
|
||||
|
||||
def must_call_validators
|
||||
MUST_CALL_VALIDATORS
|
||||
end
|
||||
def model
|
||||
MODEL
|
||||
end
|
||||
def get_attributes
|
||||
GET_ATTRIBUTES
|
||||
end
|
||||
def have_children_elements
|
||||
HAVE_CHILDREN_ELEMENTS
|
||||
end
|
||||
def need_initialize_variables
|
||||
NEED_INITIALIZE_VARIABLES
|
||||
end
|
||||
def plural_forms
|
||||
PLURAL_FORMS
|
||||
end
|
||||
|
||||
|
||||
def inherited(klass)
|
||||
klass.const_set("MUST_CALL_VALIDATORS", {})
|
||||
klass.const_set("MODEL", [])
|
||||
klass.const_set("GET_ATTRIBUTES", [])
|
||||
klass.const_set("HAVE_CHILDREN_ELEMENTS", [])
|
||||
klass.const_set("NEED_INITIALIZE_VARIABLES", [])
|
||||
klass.const_set("PLURAL_FORMS", {})
|
||||
|
||||
klass.module_eval(<<-EOC)
|
||||
public
|
||||
|
||||
@tag_name = name.split(/::/).last
|
||||
@tag_name[0,1] = @tag_name[0,1].downcase
|
||||
@indent_size = name.split(/::/).size - 2
|
||||
|
||||
@@must_call_validators = {}
|
||||
@have_content = false
|
||||
|
||||
def self.must_call_validators
|
||||
@@must_call_validators
|
||||
super.merge(MUST_CALL_VALIDATORS)
|
||||
end
|
||||
def self.model
|
||||
MODEL + super
|
||||
end
|
||||
def self.get_attributes
|
||||
GET_ATTRIBUTES + super
|
||||
end
|
||||
def self.have_children_elements
|
||||
HAVE_CHILDREN_ELEMENTS + super
|
||||
end
|
||||
def self.need_initialize_variables
|
||||
NEED_INITIALIZE_VARIABLES + super
|
||||
end
|
||||
def self.plural_forms
|
||||
super.merge(PLURAL_FORMS)
|
||||
end
|
||||
|
||||
|
||||
def self.install_must_call_validator(prefix, uri)
|
||||
@@must_call_validators[uri] = prefix
|
||||
MUST_CALL_VALIDATORS[uri] = prefix
|
||||
end
|
||||
|
||||
@@model = []
|
||||
|
||||
def self.model
|
||||
@@model
|
||||
end
|
||||
|
||||
def self.install_model(tag, occurs=nil)
|
||||
if m = @@model.find {|t, o| t == tag}
|
||||
if m = MODEL.find {|t, o| t == tag}
|
||||
m[1] = occurs
|
||||
else
|
||||
@@model << [tag, occurs]
|
||||
MODEL << [tag, occurs]
|
||||
end
|
||||
end
|
||||
|
||||
@@get_attributes = []
|
||||
|
||||
def self.get_attributes()
|
||||
@@get_attributes
|
||||
end
|
||||
|
||||
def self.install_get_attribute(name, uri, required=true)
|
||||
attr_writer name
|
||||
convert_attr_reader name
|
||||
@@get_attributes << [name, uri, required]
|
||||
GET_ATTRIBUTES << [name, uri, required]
|
||||
end
|
||||
|
||||
@@have_content = false
|
||||
|
||||
def self.content_setup
|
||||
attr_writer :content
|
||||
convert_attr_reader :content
|
||||
def_content_only_to_s
|
||||
@@have_content = true
|
||||
@have_content = true
|
||||
end
|
||||
|
||||
def self.have_content?
|
||||
@@have_content
|
||||
end
|
||||
|
||||
@@have_children_elements = []
|
||||
|
||||
def self.have_children_elements
|
||||
@@have_children_elements
|
||||
@have_content
|
||||
end
|
||||
|
||||
def self.add_have_children_element(variable_name, plural_name)
|
||||
@@have_children_elements << [variable_name, plural_name]
|
||||
HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
|
||||
end
|
||||
|
||||
@@need_initialize_variables = []
|
||||
|
||||
def self.add_need_initialize_variable(variable_name)
|
||||
@@need_initialize_variables << variable_name
|
||||
NEED_INITIALIZE_VARIABLES << variable_name
|
||||
end
|
||||
|
||||
def self.need_initialize_variables
|
||||
@@need_initialize_variables
|
||||
end
|
||||
|
||||
@@plural_forms = {}
|
||||
|
||||
def self.add_plural_form(singular, plural)
|
||||
@@plural_forms[singular] = plural
|
||||
end
|
||||
|
||||
def self.plural_forms
|
||||
@@plural_forms
|
||||
PLURAL_FORMS[singular] = plural
|
||||
end
|
||||
|
||||
EOC
|
||||
|
|
41
test/rss/test_inherit.rb
Normal file
41
test/rss/test_inherit.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
|
||||
module RSS
|
||||
class TestInherit < TestCase
|
||||
|
||||
class InheritedImage < RSS::RDF::Image
|
||||
def self.indent_size; 1; end
|
||||
def self.tag_name; 'image'; end
|
||||
end
|
||||
|
||||
def setup
|
||||
@rss = make_RDF(<<-EOR)
|
||||
#{make_channel}
|
||||
#{make_image}
|
||||
#{make_item}
|
||||
#{make_textinput}
|
||||
EOR
|
||||
end
|
||||
|
||||
def test_inherit
|
||||
rss = RSS::Parser.parse(@rss)
|
||||
orig_image = rss.image
|
||||
prefix = "[INHERIT]"
|
||||
image = InheritedImage.new("#{prefix} #{orig_image.about}")
|
||||
image.title = "#{prefix} #{orig_image.title}"
|
||||
image.url = "#{prefix} #{orig_image.url}"
|
||||
image.link = "#{prefix} #{orig_image.link}"
|
||||
rss.image = image
|
||||
|
||||
new_rss = RSS::Parser.parse(rss.to_s)
|
||||
new_image = new_rss.image
|
||||
assert_equal("#{prefix} #{orig_image.about}", new_image.about)
|
||||
assert_equal("#{prefix} #{orig_image.title}", new_image.title)
|
||||
assert_equal("#{prefix} #{orig_image.url}", new_image.url)
|
||||
assert_equal("#{prefix} #{orig_image.link}", new_image.link)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ require "rss-testcase"
|
|||
module RSS
|
||||
class TestVersion < TestCase
|
||||
def test_version
|
||||
assert_equal("0.1.2", ::RSS::VERSION)
|
||||
assert_equal("0.1.3", ::RSS::VERSION)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue