Module: BuildNumber
- Defined in:
- lib/build_number.rb,
lib/build_number/version.rb
Constant Summary collapse
- FILE_NAME =
'.build_number'
- VERSION =
'0.1.0-pre'
Class Method Summary collapse
- .find_or_create_file(dir = nil) ⇒ Object
- .increment(dir = nil) ⇒ Object
- .read(path) ⇒ Object
- .save(path, next_build_number = 0) ⇒ Object
- .set_env(dir = nil) ⇒ Object
Class Method Details
.find_or_create_file(dir = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/build_number.rb', line 18 def self.find_or_create_file(dir=nil) dir ||= Dir.pwd file = find_file dir file = create_file dir if file.nil? file end |
.increment(dir = nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/build_number.rb', line 10 def self.increment(dir=nil) file = find_or_create_file dir read(file).tap do |current| save file, current + 1 end end |
.read(path) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/build_number.rb', line 25 def self.read(path) file = File.open(path, 'rb') current = file.read.chomp.to_i file.close current end |
.save(path, next_build_number = 0) ⇒ Object
32 33 34 |
# File 'lib/build_number.rb', line 32 def self.save(path, next_build_number=0) open(path, 'w') { |io| io.write next_build_number.to_s } end |
.set_env(dir = nil) ⇒ Object
6 7 8 |
# File 'lib/build_number.rb', line 6 def self.set_env(dir=nil) ENV['BUILD_NUMBER'] = ENV['BUILD_NUMBER'] || increment(dir) end |