开发者

newbie asking suggestion for gem structure

I plan to write a gem t开发者_JAVA百科hat create a zip file by download from a link or get from filesystem or from a string and upload to s3. Is it a good idea I hijack the Zip module from rubyzip?

Zip::Voidzip.upload! do |zip|
  zip.add "http://example.com/example.png", :as => "image/zzz.png"
  zip.add "asdasdasdads"
  zip.add "asd/asd.png"
end

Since the code most probabily will be like this.

module Zip
  class Voidzip
    def initialize zipname
      t = Tempfile.new(zipname)
      ZipOutputStream.open(t.path) do |zos|

      end
    end
  end
end

Any suggestion for newbie that want to contribute?


Best practice is to name your gem voidzip.

If you are intending your gem to be a plugin for zip, and if zip actually supports a plugin architecture, then practice would be to name your gem zip-voidzip (but I don't think that's the case here).

Your module/namespace structure should mirror your gem's name.

If your gem is named voidzip, then I expect all of your code to be within Voidzip and I expect to be able to require "voidzip".

If your gem is named zip-voidzip, then I expect all of your code to be within Zip::Voidzip and I expect to be able to require "zip-voidzip" or require "zip/voidzip" at my choice.


// Off topic, what the OP's trying to do isn't monkeypatching per-se (see @Beerlington's comment)

I generally try to stay away from monkey-patching, unless I cannot do otherwise. It's always painful to debug something and find out that a gem creator thought it was a good idea to override functionality you're depending on.

But don't trust me, trust him, he's much more experienced that I am.

// Off topic end

You could try to be a little creative and come up with a nice gem name :-) .

Couldn't you just go with the Voidzip name, without nesting it into Zip?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜