Class: Vehicles::Configuration
- Inherits:
-
Object
- Object
- Vehicles::Configuration
- Defined in:
- lib/vehicles/configuration.rb
Overview
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Extra make aliases, merged over the built-in ones.
-
#api_base_url ⇒ Object
Base URL for the hosted VehiclesDB API.
-
#api_key ⇒ Object
Optional VehiclesDB API key.
-
#api_timeout ⇒ Object
Network timeout (seconds) for hosted API calls.
-
#cache_path ⇒ Object
Where a refreshed dataset is cached on disk.
-
#data_url ⇒ Object
Where ‘Vehicles.refresh!` pulls the latest dataset.
-
#refresh_timeout ⇒ Object
Network timeout (seconds) for a refresh download.
-
#region ⇒ Object
Default region for queries.
-
#use_cache ⇒ Object
Prefer a refreshed (cached) dataset over the bundled one when present.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vehicles/configuration.rb', line 53 def initialize @region = :eu @api_key = nil @api_base_url = "https://api.vehiclesdb.com" @api_timeout = 2 @aliases = {} @data_url = "https://cdn.jsdelivr.net/gh/vehiclesdb/vehiclesdb@latest/dist/vehicles.json" @cache_path = default_cache_path @use_cache = true @refresh_timeout = 5 end |
Instance Attribute Details
#aliases ⇒ Object
Extra make aliases, merged over the built-in ones. Keys are matched forgivingly (case/diacritics-insensitive); values are canonical make names.
31 32 33 |
# File 'lib/vehicles/configuration.rb', line 31 def aliases @aliases end |
#api_base_url ⇒ Object
Base URL for the hosted VehiclesDB API. Overridable for self-hosting/testing.
23 24 25 |
# File 'lib/vehicles/configuration.rb', line 23 def api_base_url @api_base_url end |
#api_key ⇒ Object
Optional VehiclesDB API key. When set, the hosted provider activates and enriches models with years/images/segments. When nil, everything still works on the bundled data — the gem is standalone first, SDK second.
20 21 22 |
# File 'lib/vehicles/configuration.rb', line 20 def api_key @api_key end |
#api_timeout ⇒ Object
Network timeout (seconds) for hosted API calls. Kept short so a slow/missing API never blocks a request — hosted lookups degrade to the local data.
27 28 29 |
# File 'lib/vehicles/configuration.rb', line 27 def api_timeout @api_timeout end |
#cache_path ⇒ Object
Where a refreshed dataset is cached on disk. Defaults to the app’s cache dir (Rails) or the system temp dir. The refresh writes here; loads prefer it.
44 45 46 |
# File 'lib/vehicles/configuration.rb', line 44 def cache_path @cache_path end |
#data_url ⇒ Object
Where ‘Vehicles.refresh!` pulls the latest dataset. Defaults to the public VehiclesDB data repo via jsDelivr’s CDN (always-latest release tag).
40 41 42 |
# File 'lib/vehicles/configuration.rb', line 40 def data_url @data_url end |
#refresh_timeout ⇒ Object
Network timeout (seconds) for a refresh download.
51 52 53 |
# File 'lib/vehicles/configuration.rb', line 51 def refresh_timeout @refresh_timeout end |
#region ⇒ Object
Default region for queries. Today the bundled data ships :eu; the API is already region-aware so :us/:gb/etc. are additive, never breaking.
15 16 17 |
# File 'lib/vehicles/configuration.rb', line 15 def region @region end |
#use_cache ⇒ Object
Prefer a refreshed (cached) dataset over the bundled one when present. Set false to always use the bundled snapshot (fully offline/deterministic).
48 49 50 |
# File 'lib/vehicles/configuration.rb', line 48 def use_cache @use_cache end |