Sha256: 92e9fd266bc66eac2d5cf9198854c91e76f0ebd10c38098a9c6c3d9661416a5b

Contents?: true

Size: 1.4 KB

Versions: 12

Compression:

Stored size: 1.4 KB

Contents

module Compass
  module Version
    # Returns a hash representing the version.
    # The :major, :minor, and :teeny keys have their respective numbers.
    # The :string key contains a human-readable string representation of the version.
    # If checked out from Git,
    # the :rev key will have the revision hash.
    #
    # This method swiped from Haml and then modified, some credit goes to Nathan Weizenbaum
    attr_writer :version
    def version
      return @version if defined?(@version)

      @version = {
        :string => File.read(scope('VERSION')).strip
      }
      dotted_string, label = @version[:string].split(/-/, 2)
      numbers = dotted_string.split('.').map { |n| n.to_i }
      @version[:major] = numbers[0]
      @version[:minor] = numbers[1]
      @version[:teeny] = numbers[2]
      @version[:label] = label

      if File.exists?(scope('REVISION'))
        rev = File.read(scope('REVISION')).strip
        rev = nil if rev !~ /[a-f0-9]+/
      end

      if rev.nil? && File.exists?(scope('.git/HEAD'))
        rev = File.read(scope('.git/HEAD')).strip
        if rev =~ /^ref: (.*)$/
          rev = File.read(scope(".git/#{$1}")).strip
        end
      end

      if rev
        @version[:rev] = rev
        @version[:string] << " [#{rev[0...7]}]"
      end

      @version
    end
    
    def scope(file) # :nodoc:
      File.join(File.dirname(__FILE__), '..', '..', file)
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
arnebrasseur-compass-0.3.5.1 lib/compass/version.rb
arnebrasseur-compass-0.3.5 lib/compass/version.rb
chriseppstein-compass-0.1.1 lib/compass/version.rb
chriseppstein-compass-0.3.0 lib/compass/version.rb
chriseppstein-compass-0.3.1 lib/compass/version.rb
chriseppstein-compass-0.3.2 lib/compass/version.rb
chriseppstein-compass-0.3.3 lib/compass/version.rb
chriseppstein-compass-0.3.4 lib/compass/version.rb
chriseppstein-compass-0.3.6 lib/compass/version.rb
chriseppstein-compass-0.3.7 lib/compass/version.rb
chriseppstein-compass-0.3.8 lib/compass/version.rb
chriseppstein-compass-0.3.9 lib/compass/version.rb