class Semverve::Formats::SimpleString
Handles version files that define a single top-level VERSION string.
Constants
- PATTERN
-
Pattern for locating a simple
VERSIONassignment.@return [Regexp]
Public Instance Methods
# File lib/semverve/formats/simple_string.rb, line 55 def generate(version, module_name:) <<~RUBY # frozen_string_literal: true ## # Namespace for #{module_name}. module #{module_name} ## # Full gem version string. # # @return [String] VERSION = "#{version}" end RUBY end
Generates a simple version file.
@param [Semverve::SemanticVersion] version @param [String] module_name
@return [String]
Source
# File lib/semverve/formats/simple_string.rb, line 24 def parse(content, path:) match = content.match(PATTERN) return SemanticVersion.parse(match[3]) if match raise Error, "Could not parse #{path} as simple format. Expected VERSION = \"MAJOR.MINOR.PATCH\"." end
Parses a semantic version from simple string content.
@param [String] content @param [String] path
@return [Semverve::SemanticVersion]
# File lib/semverve/formats/simple_string.rb, line 40 def replace(content, version, path:) unless content.match?(PATTERN) raise Error, "Could not parse #{path} as simple format. Expected VERSION = \"MAJOR.MINOR.PATCH\"." end content.sub(PATTERN) { "#{$1}#{$2}#{version}#{$4}" } end
Replaces the semantic version in simple string content.
@param [String] content @param [Semverve::SemanticVersion] version @param [String] path
@return [String]