Class: Safedep::Policy::SemVer

Inherits:
Object
  • Object
show all
Defined in:
lib/safedep/policy/sem_ver.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ SemVer

Returns a new instance of SemVer.



10
11
12
13
14
15
16
17
18
# File 'lib/safedep/policy/sem_ver.rb', line 10

def initialize(version)
  @version = if version.is_a?(Gem::Version)
               version
             else
               Gem::Version.new(version)
             end

  decompose_version
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



4
5
6
# File 'lib/safedep/policy/sem_ver.rb', line 4

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



4
5
6
# File 'lib/safedep/policy/sem_ver.rb', line 4

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



4
5
6
# File 'lib/safedep/policy/sem_ver.rb', line 4

def patch
  @patch
end

#suffixObject (readonly)

Returns the value of attribute suffix.



4
5
6
# File 'lib/safedep/policy/sem_ver.rb', line 4

def suffix
  @suffix
end

#versionObject (readonly)

Returns the value of attribute version.



4
5
6
# File 'lib/safedep/policy/sem_ver.rb', line 4

def version
  @version
end

Class Method Details

.version_specifiers(version) ⇒ Object



6
7
8
# File 'lib/safedep/policy/sem_ver.rb', line 6

def self.version_specifiers(version)
  new(version).version_specifiers
end

Instance Method Details

#version_specifiersObject



20
21
22
23
24
25
26
27
28
# File 'lib/safedep/policy/sem_ver.rb', line 20

def version_specifiers
  specifiers = ['~> ' + [major, minor].join('.')]
  return specifiers if satisfy_specifiers?(specifiers)

  specifiers = [">= #{version}", "< #{major.to_i + 1}"]
  return specifiers if satisfy_specifiers?(specifiers)

  nil
end