Class: Kotoshu::SourceRegistry
- Inherits:
-
Object
- Object
- Kotoshu::SourceRegistry
- Defined in:
- lib/kotoshu/source_registry.rb
Overview
Single source of truth for where each remote resource lives.
Every URL the cache layer fetches is built here. Caches do not construct URL strings inline. Per-repo pins honor that ‘kotoshu/dictionaries` ships on `v1` while the other repos are on `main`, which previously caused silent 404s on first-use.
Defined Under Namespace
Classes: Source
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://raw.githubusercontent.com/kotoshu"- SOURCES =
{ spelling: Source.new(repo: "dictionaries", default_pin: "v1", template: "dictionaries/%<pin>s/%<lang>s/spelling/index.%<ext>s"), grammar: Source.new(repo: "dictionaries", default_pin: "v1", template: "dictionaries/%<pin>s/%<lang>s/grammar/rules.yaml"), dict_manifest: Source.new(repo: "dictionaries", default_pin: "v1", template: "dictionaries/%<pin>s/manifest.json"), frequency: Source.new(repo: "frequency-list-kelly", default_pin: "main", template: "frequency-list-kelly/%<pin>s/data/%<lang>s.json"), freq_manifest: Source.new(repo: "frequency-list-kelly", default_pin: "main", template: "frequency-list-kelly/%<pin>s/manifest.json"), model: Source.new(repo: "models-fasttext-onnx", default_pin: "main", template: "models-fasttext-onnx/%<pin>s/models/%<lang>s/fasttext.%<lang>s.onnx"), model_vocab: Source.new(repo: "models-fasttext-onnx", default_pin: "main", template: "models-fasttext-onnx/%<pin>s/models/%<lang>s/fasttext.%<lang>s.vocab.json"), model_manifest: Source.new(repo: "models-fasttext-onnx", default_pin: "main", template: "models-fasttext-onnx/%<pin>s/manifest.json") }.freeze
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
Configured GitHub raw root (no trailing slash).
Instance Method Summary collapse
-
#initialize(base_url: DEFAULT_BASE_URL, pins: {}) ⇒ SourceRegistry
constructor
A new instance of SourceRegistry.
-
#pin_for_source(source_key) ⇒ String
Resolved pin (override or default).
-
#repo_for(source_key) ⇒ String
Repo name (e.g. “dictionaries”).
-
#url_for(source_key, lang: nil, ext: nil) ⇒ String
Fully-qualified URL.
Constructor Details
#initialize(base_url: DEFAULT_BASE_URL, pins: {}) ⇒ SourceRegistry
Returns a new instance of SourceRegistry.
35 36 37 38 |
# File 'lib/kotoshu/source_registry.rb', line 35 def initialize(base_url: DEFAULT_BASE_URL, pins: {}) @base_url = base_url.to_s.chomp("/") @pins = pins.transform_keys(&:to_s).freeze end |
Instance Attribute Details
#base_url ⇒ String (readonly)
Returns Configured GitHub raw root (no trailing slash).
41 42 43 |
# File 'lib/kotoshu/source_registry.rb', line 41 def base_url @base_url end |
Instance Method Details
#pin_for_source(source_key) ⇒ String
Returns Resolved pin (override or default).
57 58 59 60 |
# File 'lib/kotoshu/source_registry.rb', line 57 def pin_for_source(source_key) source = SOURCES.fetch(source_key) pin_for(source) end |
#repo_for(source_key) ⇒ String
Returns Repo name (e.g. “dictionaries”).
64 65 66 |
# File 'lib/kotoshu/source_registry.rb', line 64 def repo_for(source_key) SOURCES.fetch(source_key).repo end |
#url_for(source_key, lang: nil, ext: nil) ⇒ String
Returns Fully-qualified URL.
47 48 49 50 51 52 53 |
# File 'lib/kotoshu/source_registry.rb', line 47 def url_for(source_key, lang: nil, ext: nil) source = SOURCES.fetch(source_key) do raise ArgumentError, "unknown source: #{source_key.inspect}" end path = source.template % { pin: pin_for(source), lang: lang, ext: ext } "#{@base_url}/#{path}" end |