Files
openfoodnetwork/app/models/spree/country.rb
Maikel Linke f971131888 Cache default country for an hour
The default country usually never changes after the initial setup of an
instance.
2022-11-02 15:33:43 +11:00

24 lines
423 B
Ruby

# frozen_string_literal: true
module Spree
class Country < ApplicationRecord
has_many :states, -> { order('name ASC') }
validates :name, :iso_name, presence: true
def self.cached_find_by(attrs)
Rails.cache.fetch("countries/#{attrs.hash}", expires_in: 1.hour) do
find_by(attrs)
end
end
def <=>(other)
name <=> other.name
end
def to_s
name
end
end
end