Class: Shadwire::RegistryClient
- Inherits:
-
Object
- Object
- Shadwire::RegistryClient
- Defined in:
- lib/shadwire/registry_client.rb
Overview
Fetches the published registry over file:// or http(s)://. Both #index and #item are memoized within the instance.
Instance Method Summary collapse
-
#index ⇒ Object
Returns the parsed index.json hash (memoized).
-
#initialize(base_url) ⇒ RegistryClient
constructor
A new instance of RegistryClient.
-
#item(name) ⇒ Object
Returns the parsed name.json hash (memoized per name).
Constructor Details
#initialize(base_url) ⇒ RegistryClient
Returns a new instance of RegistryClient.
9 10 11 12 13 |
# File 'lib/shadwire/registry_client.rb', line 9 def initialize(base_url) # Normalise: drop any trailing slash so URL building is consistent. @base_url = base_url.chomp("/") @cache = {} end |
Instance Method Details
#index ⇒ Object
Returns the parsed index.json hash (memoized).
16 17 18 |
# File 'lib/shadwire/registry_client.rb', line 16 def index @cache[:__index__] ||= fetch("index.json") end |
#item(name) ⇒ Object
Returns the parsed name.json hash (memoized per name). Raises Shadwire::RegistryError if the item is not found.
22 23 24 |
# File 'lib/shadwire/registry_client.rb', line 22 def item(name) @cache[name] ||= fetch("#{name}.json", name:) end |