Sha256: 38bc88ad62c761a4f273605638e3fa3da14dd05dfd840cd5fdfcabf6cc187c69

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 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.
    # The :rev key will have the current revision hash.
    #
    # This method swiped from Haml and then modified, some credit goes to Nathan Weizenbaum
    def version
      if defined?(@version)
        @version
      else
        read_version
      end
    end

    protected

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

    def read_version
      require 'yaml'
      @version = YAML::load(File.read(scope('VERSION.yml')))
      @version[:teeny] = @version[:patch]
      @version[:string] = "#{@version[:major]}.#{@version[:minor]}.#{@version[:patch]}"
      @version[:string] << ".#{@version[:build]}" if @version[:build]
      @version
    end

    def revision
      revision_from_git
    end

    def revision_from_git
      if File.exists?(scope('.git/HEAD'))
        rev = File.read(scope('.git/HEAD')).strip
        if rev =~ /^ref: (.*)$/
          rev = File.read(scope(".git/#{$1}")).strip
        end
      end
    end
  end
  extend Compass::Version
  def self.const_missing(const)
    # This avoid reading from disk unless the VERSION is requested.
    if const == :VERSION
      version[:string]
    else
      super
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
compass-0.10.6 lib/compass/version.rb
compass-0.10.6.pre.1 lib/compass/version.rb
compass-0.10.5 lib/compass/version.rb
compass-0.10.5.pre.1 lib/compass/version.rb
compass-0.10.4 lib/compass/version.rb
compass-0.10.4.pre.4 lib/compass/version.rb
compass-0.10.4.pre.3 lib/compass/version.rb
compass-0.10.4.pre.2 lib/compass/version.rb
compass-0.10.3 lib/compass/version.rb
compass-0.10.3.pre.1 lib/compass/version.rb
compass-0.10.2 lib/compass/version.rb
compass-0.10.1 lib/compass/version.rb