Sha256: d57302623dda111a6a57f40a7505409e9ac16a8fcee7fe854c0b6370d32b6b14

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

#!/usr/bin/ruby

module NewRelic
  module VERSION #:nodoc:
    def self.parse_build_from_gemspec(path)
      if File.exist?(path)
        version_string = if Kernel.const_defined?(:Gem)
          spec = Gem::Specification.load(path)
          spec.version.to_s if spec
        else
          md = File.read(path).match(/s\.version\s*=\s*"(.*)"/)
          md[1] if md
        end
        version_string && version_string.split('.', 4)[3]
      end
    end

    GEMSPEC_PATH = File.join(File.dirname(__FILE__), '..', '..', 'newrelic_rpm.gemspec')
    MAJOR = 3
    MINOR = 5
    TINY  = 4
    BUILD = parse_build_from_gemspec(GEMSPEC_PATH)

    STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
  end

  # Helper class for managing version comparisons
  class VersionNumber
    attr_reader :parts
    include Comparable
    def initialize(version_string)
      version_string ||= '1.0.0'
      @parts = version_string.split('.').map{|n| n =~ /^\d+$/ ? n.to_i : n}
    end
    def major_version; @parts[0]; end
    def minor_version; @parts[1]; end
    def tiny_version; @parts[2]; end

    def <=>(other)
      other = self.class.new(other) if other.is_a? String
      self.class.compare(self.parts, other.parts)
    end

    def to_s
      @parts.join(".")
    end

    def hash
      @parts.hash
    end

    def eql? other
      (self <=> other) == 0
    end

    private
    def self.compare(parts1, parts2)
      a, b = parts1.first, parts2.first
      case
        when a.nil? && b.nil? then 0
        when a.nil? then b.is_a?(Fixnum) ?  -1 : 1
        when b.nil? then -compare(parts2, parts1)
        when a.to_s == b.to_s then compare(parts1[1..-1], parts2[1..-1])
        when a.is_a?(String) then b.is_a?(Fixnum) ?  -1 : (a <=> b)
        when b.is_a?(String) then -compare(parts2, parts1)
        else # they are both fixnums, not nil
          a <=> b
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
newrelic_rpm-3.5.4.35.beta lib/new_relic/version.rb
newrelic_rpm-3.5.4.34 lib/new_relic/version.rb
newrelic_rpm-3.5.4.33 lib/new_relic/version.rb
newrelic_rpm-3.5.4.31.beta lib/new_relic/version.rb
newrelic_rpm-3.5.4.29.beta lib/new_relic/version.rb