Class: GtfsReader::Version::Bumper
- Inherits:
-
Object
- Object
- GtfsReader::Version::Bumper
- Defined in:
- lib/gtfs_reader/version.rb
Overview
A helper class which bumps the version number stored in this file
Constant Summary collapse
- PARTS =
i[major minor patch]
- PATTERN =
%r[(\s+)MAJOR = \d+\s+MINOR = \d+\s+PATCH = \d+\s+BUILD = .+]
Instance Method Summary collapse
-
#bump ⇒ Object
Increase the version number and write it to this file.
-
#initialize(filename = __FILE__, part) ⇒ Bumper
constructor
A new instance of Bumper.
-
#to_s ⇒ String
What the new version string will be.
Constructor Details
#initialize(filename = __FILE__, part) ⇒ Bumper
Returns a new instance of Bumper.
24 25 26 27 |
# File 'lib/gtfs_reader/version.rb', line 24 def initialize(filename=__FILE__, part) raise "#{part} not one of #{PARTS}" unless PARTS.include? part @filename, @part = filename, part end |
Instance Method Details
#bump ⇒ Object
Increase the version number and write it to this file
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gtfs_reader/version.rb', line 30 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 #{to_s}" end |
#to_s ⇒ String
Returns What the new version string will be.
45 46 47 48 |
# File 'lib/gtfs_reader/version.rb', line 45 def to_s p = new_version [p[:major], p[:minor], p[:patch], p[:build]].compact.join ?. end |