Sha256: a80ae2ad78fa047970819b24f7568523a7710b5a0dbc66261ca102608e7f910d

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

#!/usr/bin/ruby
module NewRelic
  module VERSION #:nodoc:
    MAJOR = 2
    MINOR = 9
    TINY  = 9
    STRING = [MAJOR, MINOR, TINY].join('.')
  end
  
  # Helper class for managing version comparisons 
  class VersionNumber
    attr_reader :major_version, :minor_version, :tiny_version
    include Comparable
    def initialize(version_string)
      version_string ||= '1.0.0'
      @parts = version_string.split('.').map{|n| n.to_i }
      @major_version, @minor_version, @tiny_version = (version_string.split('.') + %w[0 0 0]).map(&:to_i)
    end
    def major_version; @parts[0]; end
    def minor_version; @parts[1]; end
    def tiny_version; @parts[2]; end
    
    def <=>(other)
      other = VersionNumber.new(other) if other.is_a?(String)
      self.scalar_value <=> other.scalar_value 
    end
    
    def eql?(other)
      return self.scalar_value == other.scalar_value rescue nil
    end
    
    def to_s
      @parts.join(".")
    end
    def scalar_value
      if !@scalar_value
        bits = 24
        @scalar_value = @parts.inject(0) do | value, part |
          bits -= 6
          value + (part << bits)
        end
      end
      @scalar_value
    end
    alias hash scalar_value
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
newrelic_rpm-2.9.9 lib/new_relic/version.rb