mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
These config values are relatively static but in some cases they can be called many times in the same request (like rendering a report or a large list of line_items in BOM). These values will now only get fetched from Redis/Postgres once at most per request/job.
20 lines
661 B
Ruby
20 lines
661 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Wraps repeatedly-called configs in a CurrentAttributes object so they only get fetched once
|
|
# per request at most, eg: CurrentConfig.get(:available_units) for Spree::Config[:available_units]
|
|
|
|
class CurrentConfig < ActiveSupport::CurrentAttributes
|
|
attribute :display_currency, :hide_cents, :currency_decimal_mark,
|
|
:currency_thousands_separator, :currency_symbol_position, :available_units
|
|
|
|
def get(config_key)
|
|
return public_send(config_key) unless public_send(config_key).nil?
|
|
|
|
public_send("#{config_key}=", Spree::Config.public_send(config_key))
|
|
end
|
|
|
|
def currency
|
|
ENV.fetch("CURRENCY")
|
|
end
|
|
end
|