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
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
Constructor Details
#initialize(gem_name, version) ⇒ Fetcher
Returns a new instance of Fetcher.
24 25 26 27 |
# File 'lib/gem/skill/fetcher.rb', line 24 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.
22 23 24 |
# File 'lib/gem/skill/fetcher.rb', line 22 def gem_name @gem_name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
22 23 24 |
# File 'lib/gem/skill/fetcher.rb', line 22 def version @version end |
Instance Method Details
#changelog ⇒ Object
47 48 49 |
# File 'lib/gem/skill/fetcher.rb', line 47 def changelog @changelog ||= local_file(*CHANGELOG_CANDIDATES) end |
#examples ⇒ Object
51 52 53 |
# File 'lib/gem/skill/fetcher.rb', line 51 def examples @examples ||= local_examples end |
#fetch_all ⇒ Object
Returns a hash of source_name => content strings (only populated keys).
30 31 32 33 34 35 36 37 |
# File 'lib/gem/skill/fetcher.rb', line 30 def fetch_all { metadata: , readme: readme, changelog: changelog, examples: examples }.compact end |
#metadata ⇒ Object
39 40 41 |
# File 'lib/gem/skill/fetcher.rb', line 39 def @metadata ||= || end |
#readme ⇒ Object
43 44 45 |
# File 'lib/gem/skill/fetcher.rb', line 43 def readme @readme ||= local_file(*README_CANDIDATES) || github_readme end |