开发者

Synchronizing Jeweler's gem version with version string in program itself

So I'm using Jeweler to maintain a little gem of mine, and it provides a set of handy rake version:* tasks for managing the version number. Jeweler apparently stores the version number in a file called VERSION, which is then read on rake gemspec. The only problem is, the actual Ruby code in the library also contains a version, which is eg. sent out in HTTP request headers created by the library:

module MediaWiki
  class << self
    def version
      "0.1.6"
    end
    .开发者_开发问答..

Any ideas for keeping these two in sync automatically? Alternatively, is there some way the MediaWiki library can query the gem it was turned into to find its own version?


Why don't you have the version method return a constant?

# lib/media_wiki/version.rb
module MediaWiki
  VERSION = "1.0.6"
end

# lib/media_wiki.rb (or wherever)
module MediaWiki
  class << self
    def version
      MediaWiki::VERSION
    end
  end
end

EDIT (in response to comment):

Also you have to update your Rakefile to use the constant:

# Rakefile
Jeweler::Tasks.new do |gemspec|
  ...
  gemspec.version     = MediaWiki::VERSION
  ...
end

Peer

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜