Module: Version

Included in:
Options
Defined in:
lib/version.rb

Overview

Methods for finding out the Riff version

Instance Method Summary collapse

Instance Method Details

#git_versionObject



5
6
7
8
9
10
11
12
# File 'lib/version.rb', line 5

def git_version
  version = `cd #{__dir__} ; git describe --dirty 2> /dev/null`.chomp
  if $CHILD_STATUS.success?
    return version
  else
    return nil
  end
end

#rubygems_versionObject



14
15
16
# File 'lib/version.rb', line 14

def rubygems_version
  return Gem::Specification.find_by_name('riffdiff').version.to_s
end

#semantify_git_version(raw) ⇒ Object

Turn git describe output into a semantic version, inspired by riff.gemspec



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/version.rb', line 19

def semantify_git_version(raw)
  return nil if raw.nil?

  return raw if raw.end_with? '-dirty'

  return (raw + '.0') if /^[0-9]+\.[0-9]+$/.match(raw)

  if /^([0-9]+\.[0-9]+)-([0-9]+)-/.match(raw)
    return "#{$1}.#{$2}"
  end

  return raw
end

#versionObject



33
34
35
36
37
38
# File 'lib/version.rb', line 33

def version
  semantic_git_version = semantify_git_version(git_version)
  return semantic_git_version unless semantic_git_version.nil?

  return rubygems_version
end