Gavin Sinclair wrote:
>> I had a thought earlier about this problem though, the general problem
> of Gem::Specification objects being created in two different ways
> (Ruby and YAML). A general solution would be this:
>
Hey, Gavin? I really think you should move away from serialization of
the Gem::Specification as a !ruby/object. I've had lots of requests for
the `from_yaml' and `initialize_yaml' stuff, which I'm kinda resistant
to. All the scenarios I've seen which demand these methods could be
solved by using a domain type.
Use to_yaml_type and YAML::add_domain_type to set this up.
class Gem::Specification
# The domain type is under your own namespace, it is a unique
# type identifier which can be versioned and outlined with schema.
def to_yaml_type
"!gems.sf.net,2004/spec"
end
# Hook the loading
YAML::add_domain_type( "gems.sf.net,2004", "spec" ) do |type, val|
# The `val' hash can be massaged here.
YAML::object_maker( Gem::Specification, val )
end
end
However, if you have a compelling argument for `from_yaml', I will
consider it.
_why