Class: Dependabot::DependencyRequirement

Inherits:
Hash
  • Object
show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/dependabot/dependency_requirement.rb

Overview

A single requirement entry within Dependency#requirements, e.g.:

{
  requirement: ">= 1.0, < 2.0",
  file: "Gemfile",
  groups: [:default],
  source: { type: "rubygems", url: "https://rubygems.org" },
  metadata: { property_name: "rails.version" } # optional
}

Subclasses Hash so it is a drop-in replacement at call sites (and in type annotations) that treat requirement entries as T::Hash[Symbol, T.untyped], while exposing typed readers for the well-known keys. New code should prefer the typed readers; hash-style access remains supported while call sites are migrated gradually.

Wire compatibility: instances serialise to JSON exactly like the plain hash they were created from, and compare equal (==/eql?/#hash) to plain hashes with the same content, so existing comparisons, Array/Set operations, and API payloads are unaffected.

Note on Hash methods: in Ruby 3+, #merge, #dup and #compact preserve this class, while #select, #reject, #except, #transform_values and #to_h return plain Hash instances. Dependency#initialize re-wraps whatever it is given, so both styles remain safe.

Constant Summary collapse

K =

The values of a requirement entry are heterogeneous and ecosystem-specific, so this bridge class is necessarily untyped at the Hash level; the typed readers below are the migration path. rubocop:disable Sorbet/ForbidTUntyped

type_member { { fixed: Symbol } }
V =
type_member { { fixed: T.untyped } }
Elem =
type_member { { fixed: [Symbol, T.untyped] } }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(hash) ⇒ Object



48
49
50
51
52
# File 'lib/dependabot/dependency_requirement.rb', line 48

def self.create(hash)
  requirement = new
  requirement.replace(hash.keys.to_h { |k| [k.to_sym, hash[k]] })
  requirement
end

Instance Method Details

#fileObject



63
64
65
# File 'lib/dependabot/dependency_requirement.rb', line 63

def file
  self[:file]
end

#groupsObject



73
74
75
# File 'lib/dependabot/dependency_requirement.rb', line 73

def groups
  self[:groups]
end

#metadataObject



89
90
91
# File 'lib/dependabot/dependency_requirement.rb', line 89

def 
  self[:metadata]
end

#requirementObject



57
58
59
# File 'lib/dependabot/dependency_requirement.rb', line 57

def requirement
  self[:requirement]
end

#sourceObject



82
83
84
# File 'lib/dependabot/dependency_requirement.rb', line 82

def source
  self[:source]
end