class GtfsReader::Version::Bumper
A helper class which bumps the version number stored in this file
Constants
- PARTS
- PATTERN
Public Class Methods
new(part, filename = __FILE__)
click to toggle source
@param part [String] the part of the version to bump. one of major,
minor, or patch
@param filename [String] the file to edit
# File lib/gtfs_reader/version.rb, line 24 def initialize(part, filename = __FILE__) raise "#{part} not one of #{PARTS}" unless PARTS.include? part @filename = filename @part = part end
Public Instance Methods
bump()
click to toggle source
Increase the version number and write it to this file
# File lib/gtfs_reader/version.rb, line 31 def bump parts = new_version # \1 holds a newline and the indentation from the source 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 #{self}" end
to_s()
click to toggle source
@return [String] What the new version string will be.
# File lib/gtfs_reader/version.rb, line 46 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_reader/version.rb, line 60 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_reader/version.rb, line 53 def new_version @new_version ||= { major: MAJOR, minor: MINOR, patch: PATCH, build: BUILD }.merge(new_parts) end