Class: SemverBump::VersionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/semver_bump/version_file.rb

Constant Summary collapse

LINE_MATCH =
/^\s*VERSION\s*=\s*"?'?([.\d]*\.?[a-zA-Z]{0,4}[0-9]{0,3})"?'?\s*$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ VersionFile

Returns a new instance of VersionFile.



8
9
10
11
# File 'lib/semver_bump/version_file.rb', line 8

def initialize(filepath)
  @filepath = filepath
  setup
end

Instance Attribute Details

#semverObject

Returns the value of attribute semver.



4
5
6
# File 'lib/semver_bump/version_file.rb', line 4

def semver
  @semver
end

Instance Method Details

#replaceObject



29
30
31
32
33
# File 'lib/semver_bump/version_file.rb', line 29

def replace
  replace = @text.gsub(Regexp.new(version_string), semver.to_s)
  File.open(@filepath, "w") {|file| file.puts replace}
  semver.to_s
end

#setupObject



13
14
15
16
# File 'lib/semver_bump/version_file.rb', line 13

def setup
  @text = File.read(@filepath)
  @semver = SemVer.new(version_string)
end

#version_stringObject



25
26
27
# File 'lib/semver_bump/version_file.rb', line 25

def version_string
  LINE_MATCH.match(@text).captures.first  
end