Class: Bundle::Patch::Audit::Advisory

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle/patch/audit/advisory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Advisory

Returns a new instance of Advisory.



11
12
13
14
15
16
# File 'lib/bundle/patch/audit/advisory.rb', line 11

def initialize(raw)
  @raw              = raw
  @name             = raw.dig("gem", "name")
  @version          = Gem::Version.new(raw.dig("gem", "version"))
  @patched_versions = Array(raw.dig("advisory", "patched_versions")).map { Gem::Requirement.new(_1) }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/bundle/patch/audit/advisory.rb', line 9

def name
  @name
end

#patched_versionsObject (readonly)

Returns the value of attribute patched_versions.



9
10
11
# File 'lib/bundle/patch/audit/advisory.rb', line 9

def patched_versions
  @patched_versions
end

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'lib/bundle/patch/audit/advisory.rb', line 9

def raw
  @raw
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/bundle/patch/audit/advisory.rb', line 9

def version
  @version
end

Instance Method Details

#latest_patch_versionObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bundle/patch/audit/advisory.rb', line 22

def latest_patch_version
  @latest_patch_version ||= begin
    candidates = patched_versions.flat_map(&:requirements)
      .map { |op, v| Gem::Version.new(v) if op == ">=" }
      .compact

    candidates
      .select { |v| v.segments[0..1] == version.segments[0..1] } # Same major.minor
      .max
  end
end

#patchable?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bundle/patch/audit/advisory.rb', line 18

def patchable?
  latest_patch_version && (latest_patch_version.segments[1] == version.segments[1])
end

#to_hObject



34
35
36
# File 'lib/bundle/patch/audit/advisory.rb', line 34

def to_h
  @raw
end