Class: GtfsEngine::Version::Bumper

Inherits:
Object
  • Object
show all
Defined in:
lib/gtfs_engine/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 = .+/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(filename = __FILE__, part) ⇒ Bumper

Returns a new instance of Bumper.



20
21
22
23
24
25
# File 'lib/gtfs_engine/version.rb', line 20

def initialize(filename = __FILE__, part)
  raise "#{part} not one of #{PARTS}" unless PARTS.include?(part)

  @filename = filename
  @part = part
end

Instance Method Details

#bumpObject

Increase the version number and write it to this file



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gtfs_engine/version.rb', line 28

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 #{self}"
end

#to_sString

Returns What the new version string will be.

Returns:

  • (String)

    What the new version string will be.



42
43
44
45
# File 'lib/gtfs_engine/version.rb', line 42

def to_s
  p = new_version
  [p[:major], p[:minor], p[:patch], p[:build]].compact.join('.')
end