Class: Semvruler::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/semvruler/constraint.rb

Defined Under Namespace

Classes: FormatError

Constant Summary collapse

FORMAT =
/^((?<type>=|!=|~>|>=|>|<=|<)\s*)?(?<version>.*)$/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, version) ⇒ Constraint

Returns a new instance of Constraint.



47
48
49
50
# File 'lib/semvruler/constraint.rb', line 47

def initialize(type, version)
  @type = type
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



41
42
43
# File 'lib/semvruler/constraint.rb', line 41

def version
  @version
end

Class Method Details

.parse(value, safe: true) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/semvruler/constraint.rb', line 14

def parse(value, safe: true)
  if value.respond_to?(:map)
    value.map { |item| cast(item, safe) }
  else
    cast(value, safe)
  end
end

Instance Method Details

#match?(other) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/semvruler/constraint.rb', line 56

def match?(other)
  other = Semversion.parse(other, safe: false)
  other.send(operation, version)
end

#to_sObject



43
44
45
# File 'lib/semvruler/constraint.rb', line 43

def to_s
  "#{type_as_string}#{version}"
end

#typeObject



52
53
54
# File 'lib/semvruler/constraint.rb', line 52

def type
  @type || '='
end