Class: GtfsReader::Version::Bumper

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(filename = __FILE__, part) ⇒ Bumper

Returns a new instance of Bumper.

Parameters:

  • filename (String) (defaults to: __FILE__)

    the file to edit

  • part (String)

    the part of the version to bump. one of major, minor, or patch



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

#bumpObject

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_sString

Returns What the new version string will be.

Returns:

  • (String)

    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