Patches: Browse | Submit New | Admin

[#24392] support module-based VERSION strings

Date:
2009-03-08 04:16
Priority:
3
Submitted By:
Stephen Bannasch (stepheneb)
Assigned To:
Eric Hodel (drbrain)
Category:
other
State:
Closed
Summary:
support module-based VERSION strings

Detailed description
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: Notepad

Please login


Followup

Message
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.

Attached Files:

Name Description Download
0001-support-module-based-VERSION-strings.patch 0001-support-module-based-VERSION-strings.patch Download
0002-support-module-based-VERSION-strings.patch updated pathc Download
0003-support-module-based-VERSION-strings.patch 0003-support-module-based-VERSION-strings.patch Download

Changes:

Field Old Value Date By
resolution_idNone2009-03-26 00:24drbrain
status_idOpen2009-03-26 00:24drbrain
close_date2009-03-26 00:242009-03-26 00:24drbrain
File Added4415: 0003-support-module-based-VERSION-strings.patch2009-03-10 04:59stepheneb
assigned_tonone2009-03-09 21:37drbrain
category_idNone2009-03-09 21:37drbrain
artifact_group_idNone2009-03-09 21:37drbrain
File Added4401: 0002-support-module-based-VERSION-strings.patch2009-03-08 04:47stepheneb
File Added4400: 0001-support-module-based-VERSION-strings.patch2009-03-08 04:24stepheneb