Class: Wabi::RegistryClient
- Inherits:
-
Object
- Object
- Wabi::RegistryClient
- Defined in:
- lib/wabi/registry_client.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://wabikit.dev/r"- DEFAULT_TTL =
24 * 60 * 60
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #fetch(component_name) ⇒ Object
-
#initialize(base_url: DEFAULT_BASE_URL) ⇒ RegistryClient
constructor
A new instance of RegistryClient.
Constructor Details
#initialize(base_url: DEFAULT_BASE_URL) ⇒ RegistryClient
Returns a new instance of RegistryClient.
16 17 18 19 |
# File 'lib/wabi/registry_client.rb', line 16 def initialize(base_url: DEFAULT_BASE_URL) @base_url = base_url @ttl = Integer(ENV.fetch("WABI_CACHE_TTL", DEFAULT_TTL)) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
14 15 16 |
# File 'lib/wabi/registry_client.rb', line 14 def base_url @base_url end |
Instance Method Details
#cache_dir ⇒ Object
21 22 23 |
# File 'lib/wabi/registry_client.rb', line 21 def cache_dir File.("~/.cache/wabi/#{Wabi::VERSION}") end |
#fetch(component_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wabi/registry_client.rb', line 25 def fetch(component_name) unless dev_context? cached = read_cache(component_name) return JSON.parse(cached) if cached end body = if @base_url.start_with?("file://") fetch_local(component_name) else fetch_http(component_name) end write_cache(component_name, body) unless dev_context? JSON.parse(body) end |