Ross Bamford
1/5/2006 11:19:00 PM
On Thu, 05 Jan 2006 16:09:39 -0000, Jim <narf968@gmail.com> wrote:
> $ ruby -v
> ruby 1.8.4 (2005-12-24) [i686-linux]
>
I don't think it's a bug, just that HTTPClient has a Method in one of it's
instance variables, and YAML doesn't have a way to load them (rightly so,
of course). Try this:
require "http-access2"
require "yaml"
class HTTPClient
def to_yaml( opts = {} )
YAML.quick_emit( self.id, opts ) { |out|
out.map( "!contrived.cxm,2006-01-05" ) { |map|
instance_variables.sort.each { |iv|
value = instance_eval(iv)
map.add(iv[1..-1], value) unless value.is_a? Method
}
}
}
end
end
YAML.add_domain_type( "contrived.cxm,2006-01-05", "httpClient" ) { |type,
val|
YAML.object_maker( HTTPClient, val )
}
client = HTTPClient.new
File.open("client.yml", "w") do |file|
file.puts client.to_yaml
end
client2 = YAML.load( File.read( "client.yml" ))
p client2
I should say, however, that you really shouldn't use this - the client is
undoubtedly broken (it's not keeping Methods in instance vars for nothing)
so it wouldn't work. It's just to show that's where (I think) the problem
lies.
--
Ross Bamford - rosco@roscopeco.remove.co.uk