[Rubygems-developers] Overhaul of specification.rb

why the lucky stiff rubygems-dev at whytheluckystiff.net
Sun Aug 15 10:44:13 EDT 2004

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

     # 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 )

However, if you have a compelling argument for `from_yaml', I will 
consider it.


More information about the Rubygems-developers mailing list