Sha256: d8cc35ba8452a257f3f4fb536d20c161588100dfad1f6d0e66a3c03d942c913a

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

require 'puppet'

module Puppet::Util::Package
    def versioncmp(version_a, version_b)
        vre = /[-.]|\d+|[^-.\d]+/
        ax = version_a.scan(vre)
        bx = version_b.scan(vre)

        while (ax.length>0 && bx.length>0) do
            a = ax.shift
            b = bx.shift

            if( a == b )                 then next
            elsif (a == '-' && b == '-') then next 
            elsif (a == '-')             then return -1
            elsif (b == '-')             then return 1
            elsif (a == '.' && b == '.') then next 
            elsif (a == '.' )            then return -1
            elsif (b == '.' )            then return 1
            elsif (a =~ /^\d+$/ && b =~ /^\d+$/) then
                if( a =~ /^0/ or b =~ /^0/ ) then
                    return a.to_s.upcase <=> b.to_s.upcase
                end
                return a.to_i <=> b.to_i
            else 
                return a.upcase <=> b.upcase
            end
        end
        return version_a <=> version_b;
    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puppet-0.23.0 lib/puppet/util/package.rb
puppet-0.22.4 lib/puppet/util/package.rb
puppet-0.23.1 lib/puppet/util/package.rb
puppet-0.24.0 lib/puppet/util/package.rb
puppet-0.23.2 lib/puppet/util/package.rb
puppet-0.24.1 lib/puppet/util/package.rb
puppet-0.24.4 lib/puppet/util/package.rb
puppet-0.24.3 lib/puppet/util/package.rb
puppet-0.24.2 lib/puppet/util/package.rb
puppet-0.24.5 lib/puppet/util/package.rb
puppet-0.24.7 lib/puppet/util/package.rb
puppet-0.24.6 lib/puppet/util/package.rb