Class: Bundle::Patch::Audit::Advisory
- Inherits:
-
Object
- Object
- Bundle::Patch::Audit::Advisory
- Defined in:
- lib/bundle/patch/audit/advisory.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#patched_versions ⇒ Object
readonly
Returns the value of attribute patched_versions.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(raw) ⇒ Advisory
constructor
A new instance of Advisory.
- #latest_patch_version ⇒ Object
- #patchable? ⇒ Boolean
- #to_h ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/bundle/patch/audit/advisory.rb', line 9 def name @name end |
#patched_versions ⇒ Object (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 |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
9 10 11 |
# File 'lib/bundle/patch/audit/advisory.rb', line 9 def raw @raw end |
#version ⇒ Object (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_version ⇒ Object
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
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_h ⇒ Object
34 35 36 |
# File 'lib/bundle/patch/audit/advisory.rb', line 34 def to_h @raw end |