class GtfsEngine::Version::Bumper
A helper class which bumps the version number stored in this file
Constants
- PARTS
- PATTERN
Public Class Methods
new(filename=__FILE__, part)
click to toggle source
# File lib/gtfs_engine/version.rb, line 32 def initialize(filename=__FILE__, part) raise "#{part} not one of #{PARTS}" unless PARTS.include? part @filename, @part = filename, part end
Public Instance Methods
bump()
click to toggle source
Increase the version number and write it to this file
# File lib/gtfs_engine/version.rb, line 38 def bump parts = new_version text = '\1' + ["MAJOR = #{parts[:major]}", "MINOR = #{parts[:minor]}", "PATCH = #{parts[:patch]}", "BUILD = #{parts[:build] || 'nil'}"].join( '\1' ) out_data = File.read( @filename ).gsub PATTERN, text #puts out_data File.open( @filename, 'w' ) { |out| out << out_data } puts "Bumped version to #{to_s}" end
to_s()
click to toggle source
@return [String] What the new version string will be.
# File lib/gtfs_engine/version.rb, line 52 def to_s p = new_version [p[:major], p[:minor], p[:patch], p[:build]].compact.join ?. end
Private Instance Methods
new_parts()
click to toggle source
# File lib/gtfs_engine/version.rb, line 66 def new_parts case @part when :major then { major: MAJOR + 1, minor: 0, patch: 0 } when :minor then { minor: MINOR + 1, patch: 0 } else { patch: PATCH + 1 } end end
new_version()
click to toggle source
# File lib/gtfs_engine/version.rb, line 59 def new_version @vers ||= { major: MAJOR, minor: MINOR, patch: PATCH, build: BUILD }.merge new_parts end