Class: RakeDotNet::Versioner

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_dotnet.rb

Instance Method Summary collapse

Constructor Details

#initialize(template_file = nil, opts = {}) ⇒ Versioner

Returns a new instance of Versioner.



1178
1179
1180
1181
1182
# File 'lib/rake_dotnet.rb', line 1178

def initialize(template_file=nil, opts={})
	tf_path = template_file || 'version.template.txt'
	@tf = Pathname.new(tf_path)
	@vf = Pathname.new(tf_path.sub('.template', ''))
end

Instance Method Details

#buildObject



1196
1197
1198
1199
1200
# File 'lib/rake_dotnet.rb', line 1196

def build
	bn = ENV['BUILD_NUMBER']
	return 0 if bn == nil || !bn.match(/\d+/)
	return bn
end

#getObject



1184
1185
1186
1187
1188
1189
1190
# File 'lib/rake_dotnet.rb', line 1184

def get
	return @vf.read.chomp if @vf.exist?

	v = "#{maj_min}.#{build}.#{revision}"
	@vf.open('w') {|f| f.write(v) }
	return v
end

#maj_minObject



1192
1193
1194
# File 'lib/rake_dotnet.rb', line 1192

def maj_min
	return @tf.read.chomp
end

#revisionObject



1202
1203
1204
1205
1206
1207
1208
1209
# File 'lib/rake_dotnet.rb', line 1202

def revision
	if (Pathname.new('.svn').exist?)
		return SvnInfo.new(:path => PRODUCT_ROOT).revision
	else
		# TODO: return something numeric but sane for non-numeric revision numbers (eg DVCSs)
		return '0' # YYYYMMDD is actually invalid for a {revision} number.
	end
end