ruby

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 New

func New() *Decomposer

New returns a ready-to-use Ruby decomposer.

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 is ExtractWithContext with a background context, for a caller that has none to give.

func (*Decomposer) ExtractWithContext added in v0.4.1

func (d *Decomposer) ExtractWithContext(ctx context.Context, opts *api.DecomposerOptions) (*sbom.NodeList, error)

ExtractWithContext 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) GenerationContext added in v0.4.1

func (d *Decomposer) GenerationContext() api.GenerationContext

GenerationContext says in what context the decomposer's data is read: Gemfile.lock, as it stands in the source tree.

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

func (s *GemSpec) FullVersion() string

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

type RubyGemsClient struct {
	Agent   *khttp.Agent
	BaseURL string

	// Logger is where the client says what went wrong with its requests.
	// The decomposer sets it to its caller's; left nil, nothing is logged.
	Logger *clog.Logger
}

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. The caller's logger is told of them, once.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL