Class: Dependabot::Swift::NativeRequirement

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/swift/native_requirement.rb

Constant Summary collapse

REGEXP =

TODO: Support pinning to specific revisions

/(from.*|\.upToNextMajor.*|\.upToNextMinor.*|".*"\s*\.\.[\.<]\s*".*"|exact.*|\.exact.*)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(declaration) ⇒ NativeRequirement

Returns a new instance of NativeRequirement.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dependabot/swift/native_requirement.rb', line 29

def initialize(declaration)
  @declaration = declaration

  min, max = parse_declaration(declaration)

  constraint = if min == max
                 ["= #{min}"]
               elsif closed_range?
                 [">= #{min}", "<= #{max}"]
               else
                 [">= #{min}", "< #{max}"]
               end

  @min = min
  @max = max
  @requirement = Requirement.new(constraint)
end

Instance Attribute Details

#declarationObject (readonly)

Returns the value of attribute declaration.



13
14
15
# File 'lib/dependabot/swift/native_requirement.rb', line 13

def declaration
  @declaration
end

Class Method Details

.map_requirements(requirements) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dependabot/swift/native_requirement.rb', line 15

def self.map_requirements(requirements)
  requirements.map do |requirement|
    declaration = new(requirement[:metadata][:requirement_string])

    new_declaration = yield(declaration)
    new_requirement = new(new_declaration)

    requirement.merge(
      requirement: new_requirement.to_s,
      metadata: { requirement_string: new_declaration }
    )
  end
end

Instance Method Details

#to_sObject



47
48
49
# File 'lib/dependabot/swift/native_requirement.rb', line 47

def to_s
  requirement.to_s
end

#update(version) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/dependabot/swift/native_requirement.rb', line 57

def update(version)
  if single_version_declaration?
    declaration.sub(min, version.to_s)
  elsif closed_range?
    declaration.sub(max, version.to_s)
  elsif range?
    declaration.sub(max, bump_major(version.to_s))
  end
end

#update_if_needed(version) ⇒ Object



51
52
53
54
55
# File 'lib/dependabot/swift/native_requirement.rb', line 51

def update_if_needed(version)
  return declaration if requirement.satisfied_by?(version)

  update(version)
end