mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* imported and refactored original test cases
* added methods XMLRPC::XMLParser.each_installed_parser and XMLRPC::XMLWriter.each_installed_writer to simply original test cases * use Object#allocate instead of defining an empty #initialize * module XMLRPC::Marshallable is now only used for tagging git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
67d54f209d
commit
396b1f27ca
18 changed files with 475 additions and 31 deletions
|
@ -86,6 +86,18 @@ module XMLRPC
|
|||
|
||||
end # class XMLParser
|
||||
|
||||
Classes = [Simple, XMLParser]
|
||||
|
||||
# yields an instance of each installed XML writer
|
||||
def self.each_installed_writer
|
||||
XMLRPC::XMLWriter::Classes.each do |klass|
|
||||
begin
|
||||
yield klass.new
|
||||
rescue LoadError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end # module XMLWriter
|
||||
|
||||
class Create
|
||||
|
@ -248,7 +260,10 @@ module XMLRPC
|
|||
if Config::ENABLE_MARSHALLING and param.class.included_modules.include? XMLRPC::Marshallable
|
||||
# convert Ruby object into Hash
|
||||
ret = {"___class___" => param.class.name}
|
||||
param.__get_instance_variables.each {|name, val|
|
||||
param.instance_variables.each {|v|
|
||||
name = v[1..-1]
|
||||
val = param.instance_variable_get(v)
|
||||
|
||||
if val.nil?
|
||||
ret[name] = val if Config::ENABLE_NIL_CREATE
|
||||
else
|
||||
|
|
|
@ -112,31 +112,13 @@ module XMLRPC
|
|||
begin
|
||||
mod = Module
|
||||
klass.split("::").each {|const| mod = mod.const_get(const.strip)}
|
||||
|
||||
obj = mod.allocate
|
||||
|
||||
Thread.critical = true
|
||||
# let initialize take 0 parameters
|
||||
mod.module_eval %{
|
||||
begin
|
||||
alias __initialize initialize
|
||||
rescue NameError
|
||||
end
|
||||
def initialize; end
|
||||
}
|
||||
|
||||
obj = mod.new
|
||||
|
||||
# restore old initialize
|
||||
mod.module_eval %{
|
||||
undef initialize
|
||||
begin
|
||||
alias initialize __initialize
|
||||
rescue NameError
|
||||
end
|
||||
}
|
||||
Thread.critical = false
|
||||
|
||||
hash.delete "___class___"
|
||||
hash.each {|k,v| obj.__set_instance_variable(k, v) }
|
||||
hash.each {|key, value|
|
||||
obj.instance_variable_set("@#{ key }", value) if key =~ /^([\w_][\w_0-9]*)$/
|
||||
}
|
||||
obj
|
||||
rescue
|
||||
hash
|
||||
|
@ -801,6 +783,16 @@ module XMLRPC
|
|||
NQXMLStreamParser, NQXMLTreeParser,
|
||||
REXMLStreamParser, XMLScanStreamParser]
|
||||
|
||||
# yields an instance of each installed parser
|
||||
def self.each_installed_parser
|
||||
XMLRPC::XMLParser::Classes.each do |klass|
|
||||
begin
|
||||
yield klass.new
|
||||
rescue LoadError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end # module XMLParser
|
||||
|
||||
|
||||
|
|
|
@ -17,13 +17,6 @@ module XMLRPC
|
|||
# key/value pair "___class___" => ClassName
|
||||
#
|
||||
module Marshallable
|
||||
def __get_instance_variables
|
||||
instance_variables.collect {|var| [var[1..-1], eval(var)] }
|
||||
end
|
||||
|
||||
def __set_instance_variable(key, value)
|
||||
eval("@#$1 = value") if key =~ /^([\w_][\w_0-9]*)$/
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue