Documentation
¶
Overview ¶
Package ruby implements dependency extraction for Ruby codebases managed by Bundler. The lockfile carries the resolved graph inline — every spec lists its dependencies — and, from Bundler 2.6 with checksums enabled, the sha256 of every artifact. What it does not carry is groups: the Gemfile is executable Ruby, so the lock only knows which gems are direct, not which of those are development-only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decomposer ¶
type Decomposer struct{}
Decomposer reads dependency data from Ruby codebases managed by Bundler.
func (*Decomposer) DefaultOptions ¶
func (d *Decomposer) DefaultOptions() any
DefaultOptions returns the default options for the Ruby decomposer.
func (*Decomposer) Extract ¶
func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
Extract reads Gemfile.lock and builds the graph the target platform sees.
func (*Decomposer) FindCodeBases ¶
func (d *Decomposer) FindCodeBases(index *code.PathIndex) ([]string, error)
FindCodeBases locates Ruby codebases by their Gemfile.lock files.
func (*Decomposer) Requirements ¶
func (d *Decomposer) Requirements(_ *api.DecomposerOptions) []api.Requirement
Requirements returns nothing: extraction is pure Go, offline.
type GemLockfile ¶
type GemLockfile struct {
// Sources are the lock's spec blocks: the registry (GEM), git
// repositories (GIT) and local paths (PATH), each holding the specs
// resolved from it.
Sources []*GemSource
// Platforms are the platforms the lock resolves for.
Platforms []string
// Dependencies are the direct requirements (the DEPENDENCIES
// section): every gem the Gemfile names, whatever its group.
Dependencies []string
// Checksums maps "name version[-platform]" to the artifact's sha256,
// present when the lock was written with checksums (Bundler 2.6+).
Checksums map[string]string
// BundledWith is the Bundler version that wrote the lock.
BundledWith string
}
GemLockfile is a parsed Gemfile.lock.
func ParseGemLockfile ¶
func ParseGemLockfile(data []byte) (*GemLockfile, error)
ParseGemLockfile reads a Gemfile.lock document. The format is indented text: unindented section headers, source attributes at two spaces, specs at four and their dependencies at six.
func ReadGemLockfile ¶
func ReadGemLockfile(workDir string) (*GemLockfile, error)
ReadGemLockfile reads a Gemfile.lock from a directory.
type GemSource ¶
type GemSource struct {
// Type is "gem", "git" or "path".
Type string
// Remote is the registry URL, repository URL or local path.
Remote string
// Revision, Tag and Branch pin a git source; Revision is the exact
// commit.
Revision string
Tag string
Branch string
Specs []*GemSpec
}
GemSource is one spec block.
type GemSpec ¶
type GemSpec struct {
Name string
Version string
// Platform is the variant's platform ("x86_64-linux-gnu"), empty for
// the pure-Ruby variant. The same gem and version may appear once per
// platform the lock covers.
Platform string
// Dependencies are the names the spec depends on; the lock resolves a
// name to exactly one version, so names are edges.
Dependencies []string
// Source points back at the block the spec came from.
Source *GemSource
}
GemSpec is one resolved gem.
func (*GemSpec) FullVersion ¶
FullVersion returns the version as the lock spells it, platform suffix included: the form the checksum table is keyed by.
type Options ¶
type Options struct {
// Platform targets an operating system and architecture, as os[/arch]
// in Go's vocabulary; it selects among a gem's platform variants and
// outranks the generic --platform. Empty means the platform unpack
// runs on.
Platform string
// Concurrency controls the parallel requests to rubygems.org when
// enriching (default: 10).
Concurrency int
}
Options configures the Ruby dependency extraction.
type RubyGemsClient ¶
RubyGemsClient fetches gem metadata from the rubygems.org API.
func NewRubyGemsClient ¶
func NewRubyGemsClient(concurrency int) *RubyGemsClient
NewRubyGemsClient creates a client for the rubygems.org API.
func (*RubyGemsClient) FetchAll ¶
func (c *RubyGemsClient) FetchAll(specs []*GemSpec) map[*GemSpec]*gemVersionInfo
FetchAll fetches metadata for the gems in parallel. Failures are skipped: enrichment adds what it can and never breaks an extraction.