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].freeze
- PATTERN =
/(\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(part, filename = __FILE__) ⇒ Bumper
constructor
A new instance of Bumper.
-
#to_s ⇒ String
What the new version string will be.
Constructor Details
Instance Method Details
#bump ⇒ Object
Increase the version number and write it to this file
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 ⇒ String
Returns What the new version string will be.
46 47 48 49 |
# 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 |