mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
This simplifies the code, avoids a method naming collision with Rails and should be faster as well.
20 lines
397 B
Ruby
20 lines
397 B
Ruby
# frozen_string_literal: true
|
|
|
|
class DefaultCountry
|
|
def self.id
|
|
country.id
|
|
end
|
|
|
|
def self.code
|
|
country.iso
|
|
end
|
|
|
|
def self.country
|
|
# Changing ENV requires restarting the process.
|
|
iso = ENV.fetch("DEFAULT_COUNTRY_CODE", nil)
|
|
|
|
# When ENV changes on restart, this cache will be reset as well.
|
|
@country ||= Spree::Country.find_by(iso:) || Spree::Country.first
|
|
end
|
|
end
|