Class: Gem::Skill::Fetcher
- Inherits:
-
Object
- Object
- Gem::Skill::Fetcher
- Defined in:
- lib/gem/skill/fetcher.rb
Overview
Fetches documentation for a gem from multiple sources, in priority order:
1. Local gem installation (Gem::Specification) — metadata + README + CHANGELOG + examples
2. RubyGems API — metadata only, when gem isn't installed locally
3. GitHub raw README — when gem isn't installed locally
Constant Summary collapse
- RUBYGEMS_API =
"https://rubygems.org/api/v1/gems/%s.json"- GITHUB_RAW =
"https://raw.githubusercontent.com/%s/%s/%s"- MAX_REDIRECTS =
5- OPEN_TIMEOUT =
5- READ_TIMEOUT =
10- README_CANDIDATES =
%w[README.md README.rdoc README.txt README].freeze
- CHANGELOG_CANDIDATES =
%w[CHANGELOG.md CHANGELOG.rdoc HISTORY.md CHANGES.md].freeze
- SOURCE_MAX_CHARS =
Cap on concatenated source size handed to the verifier, to protect the context window on large gems. Files are added whole until the cap is hit.
150_000
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #changelog ⇒ Object
- #examples ⇒ Object
-
#fetch_all ⇒ Object
Returns a hash of source_name => content strings (only populated keys).
-
#initialize(gem_name, version) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #metadata ⇒ Object
- #readme ⇒ Object
-
#source_code ⇒ Object
The gem's actual Ruby source (lib/**/*.rb), concatenated with per-file headers.
Constructor Details
#initialize(gem_name, version) ⇒ Fetcher
Returns a new instance of Fetcher.
28 29 30 31 |
# File 'lib/gem/skill/fetcher.rb', line 28 def initialize(gem_name, version) @gem_name = gem_name @version = version end |
Instance Attribute Details
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
26 27 28 |
# File 'lib/gem/skill/fetcher.rb', line 26 def gem_name @gem_name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
26 27 28 |
# File 'lib/gem/skill/fetcher.rb', line 26 def version @version end |
Instance Method Details
#changelog ⇒ Object
51 52 53 |
# File 'lib/gem/skill/fetcher.rb', line 51 def changelog @changelog ||= local_file(*CHANGELOG_CANDIDATES) end |
#examples ⇒ Object
55 56 57 |
# File 'lib/gem/skill/fetcher.rb', line 55 def examples @examples ||= local_examples end |
#fetch_all ⇒ Object
Returns a hash of source_name => content strings (only populated keys).
34 35 36 37 38 39 40 41 |
# File 'lib/gem/skill/fetcher.rb', line 34 def fetch_all { metadata: , readme: readme, changelog: changelog, examples: examples }.compact end |
#metadata ⇒ Object
43 44 45 |
# File 'lib/gem/skill/fetcher.rb', line 43 def @metadata ||= || end |
#readme ⇒ Object
47 48 49 |
# File 'lib/gem/skill/fetcher.rb', line 47 def readme @readme ||= local_file(*README_CANDIDATES) || github_readme end |
#source_code ⇒ Object
The gem's actual Ruby source (lib/**/*.rb), concatenated with per-file headers. This is the ground truth the verifier checks the skill against. Returns nil when the gem isn't installed locally or has no lib sources — verification is only possible against installed source.
63 64 65 |
# File 'lib/gem/skill/fetcher.rb', line 63 def source_code source_bundle&.fetch(:code) end |