Module: R::Version

Defined in:
lib/rub/r/version.rb,
lib/rub/r/version-git.rb

Overview

#

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.  #
                                                                            #

Constant Summary collapse

@@cdto =
"cd '#{Pathname.new(__FILE__).realpath.dirname}'"
@@regex =
/^v([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9]+))?(-g([0-9a-f]+))?(-(dirty))?$/

Class Method Summary collapse

Class Method Details

.commitObject

Return the latest commit that is running.



53
54
55
# File 'lib/rub/r/version-git.rb', line 53

def self.commit
	`#{@@cdto}; git rev-parse HEAD`.chomp
end

.commit_dirtyObject

Commit and if it is dirty.



61
62
63
# File 'lib/rub/r/version.rb', line 61

def self.commit_dirty
	commit + ( dirty? ? '-dirty' : '' )
end

.dirty?Boolean

If anything has changed since the last commit.

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/rub/r/version-git.rb', line 58

def self.dirty?
	`#{@@cdto}; git diff --exit-code`
	$? != 0
end

.dist_from_tagObject

The number of commits from the latest version tag.



35
36
37
# 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_stringObject

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



74
75
76
# File 'lib/rub/r/version.rb', line 74

def self.info_string
	"#{slug} (#{name}) #{string}"
end

.nameObject

Pretty Program Name.



28
29
30
# File 'lib/rub/r/version.rb', line 28

def self.name
	'Rub'
end

.number_stringObject

Returns the version number as a string.



51
52
53
# File 'lib/rub/r/version.rb', line 51

def self.number_string
	version.join('.')
end

.rendered?Boolean

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.

Returns:

  • (Boolean)


69
70
71
# File 'lib/rub/r/version.rb', line 69

def self.rendered?
	false
end

.slugObject

Command name.



38
39
40
# File 'lib/rub/r/version.rb', line 38

def self.slug
	stub + R::Version.version_major
end

.stringObject

Returns a formatted version string.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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

.stubObject

Short easy-to-type name.



33
34
35
# File 'lib/rub/r/version.rb', line 33

def self.stub
	'rub'
end

.tagObject

The latest version tag.



30
31
32
# File 'lib/rub/r/version-git.rb', line 30

def self.tag
	@@tagcache ||= `#{@@cdto}; git describe --match 'v[0-9]*.*.*' --abbrev=0`.chomp
end

.verboseObject

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.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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

.versionObject

Version number as a list.

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



46
47
48
# File 'lib/rub/r/version.rb', line 46

def self.version
	[version_major, version_minor, version_patch]
end

.version_commitObject

Latest tag and current commit.



56
57
58
# File 'lib/rub/r/version.rb', line 56

def self.version_commit
	number_string + '.' + commit[0,8]
end

.version_majorObject

Major version number.



40
41
42
# File 'lib/rub/r/version-git.rb', line 40

def self.version_major
	tag.sub @@regex, '\1'
end

.version_minorObject

Minor version number.



44
45
46
# File 'lib/rub/r/version-git.rb', line 44

def self.version_minor
	tag.sub @@regex, '\2'
end

.version_patchObject

Patch number.



48
49
50
# File 'lib/rub/r/version-git.rb', line 48

def self.version_patch
	tag.sub @@regex, '\3'
end