Class: GitCompound::Component::Version::GemVersion

Inherits:
VersionStrategy show all
Defined in:
lib/git_compound/component/version/gem_version.rb

Overview

Component Gem-like version

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from VersionStrategy

#==

Constructor Details

#initialize(repository, requirement) ⇒ GemVersion

Returns a new instance of GemVersion.



9
10
11
12
13
14
15
# File 'lib/git_compound/component/version/gem_version.rb', line 9

def initialize(repository, requirement)
  raise CompoundSyntaxError, 'Malformed version requirement string' unless
    requirement =~ Gem::Requirement::PATTERN

  @repository  = repository
  @requirement = requirement
end

Instance Attribute Details

#requirementObject (readonly)

Returns the value of attribute requirement.



7
8
9
# File 'lib/git_compound/component/version/gem_version.rb', line 7

def requirement
  @requirement
end

Instance Method Details

#lastest_versionObject



17
18
19
# File 'lib/git_compound/component/version/gem_version.rb', line 17

def lastest_version
  matches.first
end

#matchesObject



29
30
31
32
33
# File 'lib/git_compound/component/version/gem_version.rb', line 29

def matches
  versions = @repository.versions
  versions.select! { |version| version.matches?(@requirement) }
  versions.sort.reverse
end

#reachable?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/git_compound/component/version/gem_version.rb', line 35

def reachable?
  matches.any?
end

#refObject



21
22
23
# File 'lib/git_compound/component/version/gem_version.rb', line 21

def ref
  lastest_version.tag
end

#shaObject



25
26
27
# File 'lib/git_compound/component/version/gem_version.rb', line 25

def sha
  lastest_version.sha
end

#to_sObject



39
40
41
# File 'lib/git_compound/component/version/gem_version.rb', line 39

def to_s
  "version: #{@requirement}"
end