diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-06-07 19:02:03 +0300 |
---|---|---|
committer | Francisco Javier López <fjlopez@gitlab.com> | 2018-06-07 19:02:03 +0300 |
commit | 5ebf884ae35307b70d6cf557a214254a8ac24af0 (patch) | |
tree | 42bfd4b1d02356b249172f6ef4ae3e26044ffa97 | |
parent | ef7cff1fda14a3b6da78602d6950e3b1d61ffc10 (diff) |
Adding Gitlab::VersionInfo file
-rw-r--r-- | changelogs/unreleased/fj-vendoring-ruby-dir.yml | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/REVISION | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/version_info.rb | 54 |
3 files changed, 56 insertions, 2 deletions
diff --git a/changelogs/unreleased/fj-vendoring-ruby-dir.yml b/changelogs/unreleased/fj-vendoring-ruby-dir.yml index f4ac4994d..2d8afe171 100644 --- a/changelogs/unreleased/fj-vendoring-ruby-dir.yml +++ b/changelogs/unreleased/fj-vendoring-ruby-dir.yml @@ -1,5 +1,5 @@ --- -title: Vendoring ruby dir to 570c4928aaca1a0842c2dfdc8240f99e72ba1fc4 +title: Vendoring ruby dir to 3b3b705ab5ca690459e40a63e101372e34f2701b merge_request: 753 author: type: other diff --git a/ruby/vendor/gitlab_git/REVISION b/ruby/vendor/gitlab_git/REVISION index a614bd6d5..ec4fa65ec 100644 --- a/ruby/vendor/gitlab_git/REVISION +++ b/ruby/vendor/gitlab_git/REVISION @@ -1 +1 @@ -570c4928aaca1a0842c2dfdc8240f99e72ba1fc4 +3b3b705ab5ca690459e40a63e101372e34f2701b diff --git a/ruby/vendor/gitlab_git/lib/gitlab/version_info.rb b/ruby/vendor/gitlab_git/lib/gitlab/version_info.rb new file mode 100644 index 000000000..6ee41e85c --- /dev/null +++ b/ruby/vendor/gitlab_git/lib/gitlab/version_info.rb @@ -0,0 +1,54 @@ +module Gitlab + class VersionInfo + include Comparable + + attr_reader :major, :minor, :patch + + def self.parse(str) + if str && m = str.match(/(\d+)\.(\d+)\.(\d+)/) + VersionInfo.new(m[1].to_i, m[2].to_i, m[3].to_i) + else + VersionInfo.new + end + end + + def initialize(major = 0, minor = 0, patch = 0) + @major = major + @minor = minor + @patch = patch + end + + def <=>(other) + return unless other.is_a? VersionInfo + return unless valid? && other.valid? + + if other.major < @major + 1 + elsif @major < other.major + -1 + elsif other.minor < @minor + 1 + elsif @minor < other.minor + -1 + elsif other.patch < @patch + 1 + elsif @patch < other.patch + -1 + else + 0 + end + end + + def to_s + if valid? + "%d.%d.%d" % [@major, @minor, @patch] + else + "Unknown" + end + end + + def valid? + @major >= 0 && @minor >= 0 && @patch >= 0 && @major + @minor + @patch > 0 + end + end +end |