Class: ConvenientService::Dependencies::Queries::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/convenient_service/dependencies/queries/version.rb,
lib/convenient_service/dependencies/queries/version/null_version.rb

Defined Under Namespace

Classes: NullVersion

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ void

Parameters:

  • value (String)


24
25
26
# File 'lib/convenient_service/dependencies/queries/version.rb', line 24

def initialize(value)
  @value = value
end

Class Method Details

.null_versionConvenientService::Dependencies::Queries::Version::NullVersion



32
33
34
# File 'lib/convenient_service/dependencies/queries/version.rb', line 32

def null_version
  @null_version ||= Version::NullVersion.new
end

Instance Method Details

#<=>(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


83
84
85
# File 'lib/convenient_service/dependencies/queries/version.rb', line 83

def <=>(other)
  gem_version <=> cast_gem_version(other)
end

#gem_versionGem::Version?

Returns:

  • (Gem::Version, nil)


65
66
67
# File 'lib/convenient_service/dependencies/queries/version.rb', line 65

def gem_version
  cast_gem_version(value)
end

#major_minorString

Returns:

  • (String)


75
76
77
# File 'lib/convenient_service/dependencies/queries/version.rb', line 75

def major_minor
  to_s[/\d+\.\d+/]
end

#major_versionConvenientService::Dependencies::Queries::Version

Examples:

Beta version is considered as lower than major version.

ConvenientService::Dependencies::Queries::Version.new("4.0.0.beta1") >= 4
# => false

That is why there is a way to compare only by the first segment of version.

ConvenientService::Dependencies::Queries::Version.new("4.0.0.beta1").major_version >= 4
# => true

Returns:



58
59
60
# File 'lib/convenient_service/dependencies/queries/version.rb', line 58

def major_version
  self.class.new(gem_version&.segments&.first.to_s)
end

#null_version?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/convenient_service/dependencies/queries/version.rb', line 40

def null_version?
  false
end

#to_sString

Returns:

  • (String)


90
91
92
# File 'lib/convenient_service/dependencies/queries/version.rb', line 90

def to_s
  gem_version.to_s
end