Class: Babushka::VersionOf

Inherits:
Object show all
Defined in:
lib/babushka/version_of.rb

Defined Under Namespace

Modules: Helpers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version = nil) ⇒ VersionOf

Returns a new instance of VersionOf.


36
37
38
39
40
41
42
43
44
45
# File 'lib/babushka/version_of.rb', line 36

def initialize name, version = nil
  @name = name.is_a?(VersionOf) ? name.name : name
  @version = if version.nil?
    name.version if name.respond_to?(:version)
  elsif version.is_a? VersionStr
    version
  else
    version.to_version
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


34
35
36
# File 'lib/babushka/version_of.rb', line 34

def name
  @name
end

#versionObject

Returns the value of attribute version


34
35
36
# File 'lib/babushka/version_of.rb', line 34

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object


56
57
58
59
60
# File 'lib/babushka/version_of.rb', line 56

def <=> other
  return nil if other.nil?
  return nil unless name == other.name
  version <=> other.version
end

#==(other) ⇒ Object


47
48
49
50
51
52
53
54
# File 'lib/babushka/version_of.rb', line 47

def == other
  if other.is_a? VersionOf
    name == other.name &&
    version == other.version
  else
    to_s == other.to_s
  end
end

#exact?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'lib/babushka/version_of.rb', line 76

def exact?
  !version.nil? && version.operator == '=='
end

#inspectObject


80
81
82
# File 'lib/babushka/version_of.rb', line 80

def inspect
  "#<VersionOf #{name}#{", v#{version}" unless version.nil?}>"
end

#matches?(other) ⇒ Boolean

Returns:

  • (Boolean)

62
63
64
65
66
67
68
# File 'lib/babushka/version_of.rb', line 62

def matches? other
  if other.is_a? VersionStr
    version.nil? || other.send(version.operator, version)
  else
    matches? other.to_version
  end
end

#to_sObject


70
71
72
73
74
# File 'lib/babushka/version_of.rb', line 70

def to_s
  # == joins with a dash to produce versions like 'rack-1.4.1'; anything
  # else joins with space like 'rack >= 1.4'.
  [name, version].compact * (exact? ? '-' : ' ')
end