Patches: Browse | Submit New | Admin
I've been using this form to create version information for my gems -- it works fine in most places a string is expected. module Jnlp #:nodoc: # VERSION = '0.0.3' module VERSION MAJOR = 0 MINOR = 0 TINY = 3 STRING = [MAJOR, MINOR, TINY].join('.') class << self def to_s STRING end def ==(arg) STRING == arg end end end end So for example I can do these operations: >> require 'lib/jnlp.rb' => true >> Jnlp::VERSION => 0.0.3 >> Jnlp::VERSION.to_s => "0.0.3" >> Jnlp::VERSION::MAJOR => 0 >> Jnlp::VERSION::MINOR => 0 >> Jnlp::VERSION::TINY => 3 But this operation used in Gem::Version.correct? wont work: >> Jnlp::VERSION[/\A\s*(\d+(\.\d+)*)*\s*\z/] NoMethodError: undefined method `[]' for 0.0.3:Module Changing Gem::Version.correct? from: def self.correct?(version) case version when Integer, /\A\s*(\d+(\.\d+)*)*\s*\z/ then true else false end end to: def self.correct?(version) case version.to_s when Integer, /\A\s*(\d+(\.\d+)*)*\s*\z/ then true else false end end allows the check for a correct form to work with a module-based implementation of a VERSION string. I'll attach a patch in a subsequent comment.
Add A Comment:
Date: 2009-03-26 00:24 Sender: Eric Hodel Applied. I don't think there are other places.
Date: 2009-03-10 04:59 Sender: Stephen Bannasch > Why doesn't the patch use VERSION_PATTERN? I have no idea -- I must have based my work on older code ??? > Is it too difficult to call #to_s on your module when calling a Gem::Version method? That's a simple solution -- I didn't think of that! Changing my hoe invocation to: Hoe.new('jnlp', Jnlp::VERSION.to_s) do |p| appears to work well. Are there places in rubygems itself where Gem::Version might be called on my gem? > Also, this patch has no tests. I'm attaching an updated patch using VERSION_PATTERN and with tests. 763 tests, 2545 assertions, 0 failures, 0 errors, 0 skips
Date: 2009-03-09 21:37 Sender: Eric Hodel Why doesn't the patch use VERSION_PATTERN? Is it too difficult to call #to_s on your module when calling a Gem::Version method? Also, this patch has no tests.
Date: 2009-03-08 04:50 Sender: Stephen Bannasch FYI: the version correct check was extended to support Integer or String in svn rev 1357, 2007-08-18.
Date: 2009-03-08 04:47 Sender: Stephen Bannasch IGNORE the first patch. I wasn't paying enough attention to the Integer element of the case. This works correctly: >> def test(v); pattern = /\A\s*(\d+(\.\d+)*)*\s*\z/; case v; when Integer, pattern then true; else pattern === v.to_s; end; end => nil >> test(Jnlp::VERSION) => true >> test(1) => true >> test('0.0.3') => true The code for Gem::Version.correct? should look like this: def self.correct?(version) pattern = /\A\s*(\d+(\.\d+)*)*\s*\z/ case version when Integer, pattern then true else pattern === version.to_s end end updated patch attached: 0002-support-module-based-VERSION- strings.patch
Date: 2009-03-08 04:20 Sender: Stephen Bannasch Patch is attached.