class BRocket::VersionFile
Constants
- FILENAME
- INITIAL_VERSION
- POS_TO_IDX
Public Instance Methods
bump(num = nil)
click to toggle source
# File lib/brocket/version_file.rb, line 29 def bump(num = nil) bump_on(:patch, num) end
bump_on(pos, num)
click to toggle source
# File lib/brocket/version_file.rb, line 62 def bump_on(pos, num) sub(Git).guard_clean current = read_file body, suffix = current.split(/-/, 2) parts = body.split(/\./) idx = POS_TO_IDX[pos] error "Invalid position #{pos.inspect}" unless idx parts[idx] = num || (parts[idx].to_i + 1).to_s ver = parts.join(".") ver << "-" << suffix if suffix write_file(ver) sub(Git).add_and_commit(filepath, "bump up #{pos.to_s} version: #{ver}") success("[git #{pos.to_s}] #{ver}") ver end
filepath()
click to toggle source
# File lib/brocket/version_file.rb, line 34 def filepath File.expand_path(config_hash['VERSION_FILE'] || 'VERSION', File.dirname(config_filepath)) end
init(version = nil)
click to toggle source
# File lib/brocket/version_file.rb, line 9 def init(version = nil) write_file(version || INITIAL_VERSION) end
major(num = nil)
click to toggle source
# File lib/brocket/version_file.rb, line 19 def major(num = nil) bump_on(:major, num) end
minor(num = nil)
click to toggle source
# File lib/brocket/version_file.rb, line 24 def minor(num = nil) bump_on(:minor, num) end
read_file()
click to toggle source
# File lib/brocket/version_file.rb, line 38 def read_file vs = config_hash['VERSION_SCRIPT'] if vs Dir.chdir(File.dirname(config_filepath)) do res = `#{vs}`.strip return $? == 0 ? res : error("Error on VERSION_SCRIPT: #{vs}") end else if File.readable?(filepath) File.read(filepath).strip else error "File not found #{filepath}. You can run `#{$0} init`" end end end
show()
click to toggle source
# File lib/brocket/version_file.rb, line 14 def show $stdout.puts(read_file) end
write_file(version)
click to toggle source
# File lib/brocket/version_file.rb, line 55 def write_file(version) File.open(filepath, "w"){|f| f.puts(version) } end