Module: Rails::Hyperdrive::BundlerArtifactDiscovery

Defined in:
lib/rails/hyperdrive/bundler_artifact_discovery.rb

Defined Under Namespace

Classes: Artifact

Constant Summary collapse

SKILL_FILE_NAMES =
["SKILL.md", "SKILL.md.erb"].freeze

Class Method Summary collapse

Class Method Details

.discover(specs: nil, warnings: []) ⇒ Object

Non-fatal problems are appended to warnings and the artifact is dropped; discovery never raises.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails/hyperdrive/bundler_artifact_discovery.rb', line 36

def discover(specs: nil, warnings: [])
  specs ||= safe_bundler_specs
  resolved = specs.each_with_object({}) { |s, h| h[s.name.to_s] = s.version }

  candidates = []
  specs.each do |spec|
    each_artifact_path(spec, warnings: warnings) do |path, type|
      artifact = parse(path, source_spec: spec, type: type, resolved: resolved, warnings: warnings)
      candidates << artifact if artifact
    end
  end

  # Collapse same-name variants within one source gem (highest
  # spec_version, path as tiebreak); never across sources — composite
  # identity is (name, source_gem).
  candidates.group_by { |a| [a.name, a.source_gem, a.artifact_type] }.map do |_key, group|
    group.max_by { |a| [Gem::Version.new(a.spec_version), a.path] }
  end
end

.install_ready_body(artifact) ⇒ Object



256
257
258
259
260
261
# File 'lib/rails/hyperdrive/bundler_artifact_discovery.rb', line 256

def install_ready_body(artifact)
  return artifact.body if artifact.skill?

  _frontmatter, rest = split_frontmatter(artifact.body)
  (rest || artifact.body).sub(/\A\n+/, "")
end