Module Haml::Version
In: lib/haml/version.rb

Handles Haml version-reporting. Haml not only reports the standard three version numbers, but its Git revision hash as well, if it was installed from Git.

Methods

version  

Included Modules

Haml::Util

Public Instance methods

Returns a hash representing the version of Haml. The `:major`, `:minor`, and `:teeny` keys have their respective numbers as Fixnums. The `:name` key has the name of the version. The `:string` key contains a human-readable string representation of the version. The `:number` key is the major, minor, and teeny keys separated by periods. If Haml is checked out from Git, the `:rev` key will have the revision hash. For example:

    {
      :string => "2.1.0.9616393",
      :rev    => "9616393b8924ef36639c7e82aa88a51a24d16949",
      :number => "2.1.0",
      :major  => 2, :minor => 1, :teeny => 0
    }

@return [Hash<Symbol, String/Fixnum>] The version hash

[Source]

    # File lib/haml/version.rb, line 27
27:     def version
28:       return @@version if defined?(@@version)
29: 
30:       numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
31:       name = File.read(scope('VERSION_NAME')).strip
32:       @@version = {
33:         :major => numbers[0],
34:         :minor => numbers[1],
35:         :teeny => numbers[2],
36:         :name => name
37:       }
38:       @@version[:number] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
39:       @@version[:string] = @@version[:number].dup
40: 
41:       if File.exists?(scope('REVISION'))
42:         rev = File.read(scope('REVISION')).strip
43:         rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
44:       end
45: 
46:       if (rev.nil? || rev == '(unknown)') && File.exists?(scope('.git/HEAD'))
47:         rev = File.read(scope('.git/HEAD')).strip
48:         if rev =~ /^ref: (.*)$/
49:           rev = File.read(scope(".git/#{$1}")).strip
50:         end
51:       end
52: 
53:       if rev
54:         @@version[:rev] = rev
55:         unless rev[0] == ?(
56:           @@version[:string] << "." << rev[0...7]
57:         end
58:         @@version[:string] << " (#{name})"
59:       end
60: 
61:       @@version
62:     end

[Validate]