Class: Vehicles::Configuration
- Inherits:
-
Object
- Object
- Vehicles::Configuration
- Defined in:
- lib/vehicles/configuration.rb,
sig/vehicles.rbs
Overview
The single source of truth for every knob. Sensible defaults mean you can use
the whole gem without ever touching this — Vehicles.configure is opt-in.
Vehicles.configure do |config|
config.region = :eu # optional default continent filter
config.api_key = ENV["VEHICLESDB_API_KEY"]
config.aliases = { "Chevy" => "Chevrolet" }
end
Instance Attribute Summary collapse
-
#aliases ⇒ Hash[String, String]
Extra make aliases, merged over the built-in ones.
-
#api_base_url ⇒ String
Base URL for the hosted VehiclesDB API.
-
#api_key ⇒ String?
Optional VehiclesDB API key.
-
#api_timeout ⇒ Integer
Network timeout (seconds) for hosted API calls.
-
#cache_path ⇒ String
Where a refreshed dataset is cached on disk.
-
#data_url ⇒ String
Where
Vehicles.refresh!pulls the latest dataset. -
#other_label ⇒ Object
Label for the "Other / not in the list" escape-hatch option, used by the
include_other:helpers and theallow_other:validators. -
#refresh_timeout ⇒ Integer
Network timeout (seconds) for a refresh download.
-
#region ⇒ Symbol
Optional default CONTINENT filter for make/model queries (:eu/:na/:as/:sa/:oc/:af).
-
#use_cache ⇒ Boolean
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.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vehicles/configuration.rb', line 63 def initialize @region = nil # no continent filter by default (global dataset) @api_key = nil @api_base_url = "https://api.vehiclesdb.com" @api_timeout = 2 @aliases = {} @other_label = "Other" @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 ⇒ Hash[String, String]
Extra make aliases, merged over the built-in ones. Keys are matched forgivingly (case/diacritics-insensitive); values are canonical make names.
34 35 36 |
# File 'lib/vehicles/configuration.rb', line 34 def aliases @aliases end |
#api_base_url ⇒ String
Base URL for the hosted VehiclesDB API. Overridable for self-hosting/testing.
26 27 28 |
# File 'lib/vehicles/configuration.rb', line 26 def api_base_url @api_base_url end |
#api_key ⇒ String?
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.
23 24 25 |
# File 'lib/vehicles/configuration.rb', line 23 def api_key @api_key end |
#api_timeout ⇒ Integer
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.
30 31 32 |
# File 'lib/vehicles/configuration.rb', line 30 def api_timeout @api_timeout end |
#cache_path ⇒ String
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.
54 55 56 |
# File 'lib/vehicles/configuration.rb', line 54 def cache_path @cache_path end |
#data_url ⇒ String
Where Vehicles.refresh! pulls the latest dataset. Defaults to the public
VehiclesDB data repo via jsDelivr's CDN (always-latest release tag).
50 51 52 |
# File 'lib/vehicles/configuration.rb', line 50 def data_url @data_url end |
#other_label ⇒ Object
Label for the "Other / not in the list" escape-hatch option, used by the
include_other: helpers and the allow_other: validators. Defaults to
"Other"; set it to your UI language (e.g. "Otro", "Autre") so the option
reads naturally. Matching is forgiving: the canonical slug "other" is always
accepted too, so a stored "Other" validates even if you later relabel it.
41 42 43 |
# File 'lib/vehicles/configuration.rb', line 41 def other_label @other_label end |
#refresh_timeout ⇒ Integer
Network timeout (seconds) for a refresh download.
61 62 63 |
# File 'lib/vehicles/configuration.rb', line 61 def refresh_timeout @refresh_timeout end |
#region ⇒ Symbol
Optional default CONTINENT filter for make/model queries
(:eu/:na/:as/:sa/:oc/:af). nil (the default) means "no filter — the whole
global dataset". Set it to scope an app to one market without passing
region: on every call. (Pre-1.0 this defaulted to :eu when the data
was EU-only; the global dataset makes "everything" the honest default.)
18 19 20 |
# File 'lib/vehicles/configuration.rb', line 18 def region @region end |
#use_cache ⇒ Boolean
Prefer a refreshed (cached) dataset over the bundled one when present. Set false to always use the bundled snapshot (fully offline/deterministic).
58 59 60 |
# File 'lib/vehicles/configuration.rb', line 58 def use_cache @use_cache end |