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
ORIGIN of the hosted VehiclesDB API — scheme + host only, no path (endpoint paths carry their own /v1 prefix, and URI.join would drop a path suffix here anyway).
-
#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.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vehicles/configuration.rb', line 65 def initialize @region = nil # no continent filter by default (global dataset) @api_key = nil @api_base_url = "https://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.
36 37 38 |
# File 'lib/vehicles/configuration.rb', line 36 def aliases @aliases end |
#api_base_url ⇒ String
ORIGIN of the hosted VehiclesDB API — scheme + host only, no path (endpoint paths carry their own /v1 prefix, and URI.join would drop a path suffix here anyway). Overridable for self-hosting/testing.
28 29 30 |
# File 'lib/vehicles/configuration.rb', line 28 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.
32 33 34 |
# File 'lib/vehicles/configuration.rb', line 32 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.
56 57 58 |
# File 'lib/vehicles/configuration.rb', line 56 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).
52 53 54 |
# File 'lib/vehicles/configuration.rb', line 52 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.
43 44 45 |
# File 'lib/vehicles/configuration.rb', line 43 def other_label @other_label end |
#refresh_timeout ⇒ Integer
Network timeout (seconds) for a refresh download.
63 64 65 |
# File 'lib/vehicles/configuration.rb', line 63 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).
60 61 62 |
# File 'lib/vehicles/configuration.rb', line 60 def use_cache @use_cache end |