From: Sean O'Dell Date: 2004-06-25T08:14:53+09:00 Subject: Re: rubygems thoughts On Thursday 24 June 2004 15:29, Gavin Sinclair wrote: > On Friday, June 25, 2004, 8:07:45 AM, Sean wrote: > > On Thursday 24 June 2004 14:01, Jim Weirich wrote: > >> Sean O'Dell said: > >> > Use YAML as the control file instead of native Ruby. I think it would > >> > make automating builds easier. Ruby is okay when you're > >> > hand-crafting, but it makes automated build creation a little dicey. > >> > Not terribly, but a little. > >> > >> Actually, the .gemspec file is optional, and I never build one for my > >> projects. I just use Rake to control the building of the > >> Gem::Specification object directly and then generate the gem from the > >> spec object. Details can be found here: > >> http://rubygems.rubyforge.org/wiki/wiki.pl?CreateAGemUsingRake > >> > >> If you want to build the spec automatically, but don't want to use Rake > >> (shame on you), just create the Gem::Specification object in your code > >> (as you would in a gemspec file). To create the gem from the > >> Gem::Spcification, just use: > >> > >> builder = Gem::Builder.new(spec).build > >> > >> If you want a yaml file out of the process, build the spec and write out > >> the results of spec.to_yaml. > > > > That sounds like what I need. Can I re-constitute the YAML into a native > > Ruby data structure and pass it to Gem::Builder.new? > > I'm sure you can, but I reckon this sounds like the more difficult way > to do things. I don't see why building a gem requires run-time > generation of its specification, beyond the package version. It > should all be known upfront. I agree, but I don't mind having to call a little code to load my own YAML and create the final .gem. If Gems had the ability to build directly from a YAML config file, that would be nice, but it's good enough for me being able to call Gem::Builder.new(spec) where spec is a data structure I just loaded from YAML. It's only 2 calls, and I'd make them from my build-generating script anyway, so I don't mind. > What actual difficulty or restriction does a normal .gemspec (or > better yet, a Rakefile gme package task) cause you? It's native Ruby code, and since I generate the .gemspec file with code, I'd prefer I was generating something with more "rules" like YAML, and that I could use the result elsewhere (like merging spec data into a web page or whatever). > BTW you asked somewhere about seeing detailed information about a gem. > If you have a gem X installed, then try this: > > gem --info X > > It will print out the spec in YAML. That works pretty much, if I can call that on any .gem file. I was thinking not so much of using the YAML data for human-reading as much as automatically pumping into other things, like web pages, or a database or whatever. > > I'd prefer that .gemspec was just static meta data and contained no > > code. But as I understand it, the .gemspec file is used to create a > > static data structure that Gem::Builder uses, so maybe that point is > > moot. I think I can load a static YAML file that I generate myself > > and pass it to Gem::Builder.new. > > I'll be interested to see how this goes. I'd be even more interested > to see if there's a reason that YAML generation is better for you. > Whether there is or there isn't, either way there's an opportunity to > document some best practices out of this. Well, two places it would be useful. One, if the YAML file could be extracted from the .gem file (which I think gem --info X does) then you can merge the information into web pages and such (think of a richer gem download web page at Rubyforge). Third-party version systems would be possible, etc. The other is, pre-build-time. As a developer, say I take my .gemspec file which is normally used only by Gems and I ssh it up to a web site somewhere, which dynamically merges the information in the .gemspec with a web page to show everyone visiting the current version, the dependencies and so on. You could even generate a script that loads the YAML and contacts RAA and updates your RAA entry with all the latest information. Also, and this is a little mystic perhaps, I find that simply using YAML whenever I can opens doors to doing other things I don't initially imagine. Sean O'Dell