Module: RESTFramework::Version

Defined in:
lib/rest_framework/version.rb

Overview

Do not use Rails-specific helper methods here (e.g., blank?) so the module can run standalone.

Constant Summary collapse

VERSION_FILEPATH =
File.expand_path("../../VERSION", __dir__)
UNKNOWN =
"0-unknown"

Class Method Summary collapse

Class Method Details

.get_version(skip_git: false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rest_framework/version.rb', line 7

def self.get_version(skip_git: false)
  # First, attempt to get the version from git.
  unless skip_git
    version = `git describe --dirty 2>/dev/null`&.strip
    return version unless !version || version.empty?
  end

  # Git failed or was skipped, so try to find a VERSION file.
  begin
    version = File.read(VERSION_FILEPATH)&.strip
    return version unless !version || version.empty?
  rescue SystemCallError
  end

  # No VERSION file, so version is unknown.
  UNKNOWN
end

.stamp_version(version = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rest_framework/version.rb', line 25

def self.stamp_version(version = nil)
  # Stamp the given version into the VERSION file, deriving it from git when none is provided.
  # Returns the stamped version so callers don't rely on the (require-time) `VERSION` constant.
  version ||= self.get_version
  if version != UNKNOWN
    File.write(VERSION_FILEPATH, version)
  end
  version
end

.unstamp_versionObject



35
36
37
# File 'lib/rest_framework/version.rb', line 35

def self.unstamp_version
  File.delete(VERSION_FILEPATH) if File.exist?(VERSION_FILEPATH)
end