From: Joel VanderWerf Date: 2012-01-26T11:18:15+09:00 Subject: Re: [ANN] "files" gem - for creating temporary files and dirs On 01/25/2012 04:50 PM, Gavin Sinclair wrote: > On Thu, Jan 26, 2012 at 7:13 AM, Joel VanderWerf > wrote: >> Here's another way to do it. (FSDB does a lot of other stuff, too...) > > Without looking, I'm going to guess that you created that library, > Joel. That immediately assures me of its quality, but I found some of > the API a little unwieldy. Yeah, it's kind of ancient (c. 2003) and could use some redesign. I hadn't used it for a few years. and the formats api felt awkward to me, too. Recently I needed it as a local alternative to Amazon S3, so at least it's 1.9.3 compatible, now. >> >> formats = [ >> FSDB::TEXT_FORMAT.when(/\.txt$|\.html$/), >> FSDB::BINARY_FORMAT.when(/\.png$/) >> ] > > formats = { /\.txt$|\.html$/ => :text, /\.png$/ => :binary } > # And should the programmer really have to specify these? Can't they > be baked in? The defaults could be better (currently the default is that .txt maps to TEXT_FORMAT and everything else is marshalled), but many formats don't have a unique ruby object representation: yaml files could be strings or objects, png could be binary strings or instances of somebody's PNG class.... Also, file extensions are not always how you want to discriminate; you might not even have file extensions, and use subdir location instead. But it should definitely be easier to turn on common formats. >> img["hello.png"] = data["hello.png"] > > I don't get a sense of what that line is doing. It's reading a binary string from data/hello.png and writing it back out to "#{dir}/img/hello.png". Which is potentially far less efficient than a file copy... >> # you can automatically serialize objects in yaml, json, or marshal: >> [...] >> json_format = FSDB::Format.new( >> /\.json$/, /\.js$/, >> :name => "JSON_FORMAT", >> :load => proc {|f| JSON.load(f)}, >> :dump => proc {|object, f| f.syswrite(JSON.dump(object))} >> ) >> tmp.formats = formats + [FSDB::YAML_FORMAT, json_format] > > Seems to me that building yaml, json and marshal capabilities into the > library would be justified and worthwhile. Sure... > I'm starting work on a project involving a lot of file and directory > manipulation, so I'll check out fsdb enthusiastically. Great! Hope it's suitable, though it's not really a general purpose file/dir manager...