module R::Version

#

This software is provided ‘as-is’, without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. #

#

Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: #

#
  1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software in # a product, an acknowledgment in the product documentation would be # appreciated but is not required. #

    #
    
  2. Altered source versions must be plainly marked as such, and must not be # misrepresented as being the original software. #

    #
    
  3. This notice may not be removed or altered from any source distribution. #

    #
    

Version info.

Public Class Methods

commit() click to toggle source

Return the latest commit that is running.

# File lib/rub/r/version-git.rb, line 53
def self.commit
        `#{@@cdto}; git rev-parse HEAD`.chomp
end
commit_dirty() click to toggle source

Commit and if it is dirty.

# File lib/rub/r/version.rb, line 61
def self.commit_dirty
        commit + ( dirty? ? '-dirty' : '' )
end
dirty?() click to toggle source

If anything has changed since the last commit.

# File lib/rub/r/version-git.rb, line 58
def self.dirty?
        `#{@@cdto}; git diff --exit-code`
        $? != 0
end
dist_from_tag() click to toggle source

The number of commits from the latest version tag.

# File lib/rub/r/version-git.rb, line 35
def self.dist_from_tag
        `#{@@cdto}; git rev-list HEAD ^#{tag} --count`.to_i
end
info_string() click to toggle source

Returns a version string in the format of the --version command switch.

# File lib/rub/r/version.rb, line 74
def self.info_string
        "#{slug} (#{name}) #{string}"
end
name() click to toggle source

Pretty Program Name.

# File lib/rub/r/version.rb, line 28
def self.name
        'Rub'
end
number_string() click to toggle source

Returns the version number as a string.

# File lib/rub/r/version.rb, line 51
def self.number_string
        version.join('.')
end
rendered?() click to toggle source

If the version information has been prerendered.

If this is false dirty information is probably pretty accurate. If this is true they might have been changed since the rendering occurred.

# File lib/rub/r/version.rb, line 69
def self.rendered?
        false
end
slug() click to toggle source

Command name.

# File lib/rub/r/version.rb, line 38
def self.slug
        stub + R::Version.version_major
end
string() click to toggle source

Returns a formatted version string.

# File lib/rub/r/version.rb, line 79
def self.string
        a = []
        
        a << number_string
        if dist_from_tag > 0
                a << dist_from_tag
                a << "g#{commit[0,8]}"
        end
        
        if dirty?
                a << 'dirty'
        end
        
        a.join '-'
end
stub() click to toggle source

Short easy-to-type name.

# File lib/rub/r/version.rb, line 33
def self.stub
        'rub'
end
tag() click to toggle source

The latest version tag.

# File lib/rub/r/version-git.rb, line 30
def self.tag
        @@tagcache ||= `#{@@cdto}; git describe --match 'v[0-9]*.*.*' --abbrev=0`.chomp
end
verbose() click to toggle source

Return a string describing the current version.

Returns an overly verbose string giving all useful (and more) information about the current state of the source.

# File lib/rub/r/version.rb, line 99
def self.verbose
        out = []
        
        out << "You are using Rub, a platform and language independent build system.\n"
        out << "https://github.com/kevincox/rub\n"
        
        out << "\n"
        
        out << "You are using commit #{commit}"
        if dirty?
                out << " but the source you are running has been modified since then"
        end
        out << ".\n"
        
        out << "Commit #{commit[0,8]} is"
        if dist_from_tag > 0
                out << " #{dist_from_tag} commits after"
        end
        out << " version #{number_string}.\n"
        
        if rendered?
                out << "\n"
                out << "NOTE: This information was accurate at the time of"
                out << " installation.  Rub can not detect changes since then."
        end
        
        out.join
end
version() click to toggle source

Version number as a list.

Returns a list of three elements with the major, minor and patch numbers respectively.

# File lib/rub/r/version.rb, line 46
def self.version
        [version_major, version_minor, version_patch]
end
version_commit() click to toggle source

Latest tag and current commit.

# File lib/rub/r/version.rb, line 56
def self.version_commit
        number_string + '.' + commit[0,8]
end
version_major() click to toggle source

Major version number.

# File lib/rub/r/version-git.rb, line 40
def self.version_major
        tag.sub @@regex, '\1'
end
version_minor() click to toggle source

Minor version number.

# File lib/rub/r/version-git.rb, line 44
def self.version_minor
        tag.sub @@regex, '\2'
end
version_patch() click to toggle source

Patch number.

# File lib/rub/r/version-git.rb, line 48
def self.version_patch
        tag.sub @@regex, '\3'
end