Files
openfoodnetwork/app/serializers/api/currency_config_serializer.rb
Matt-Yorkley c01bab5f27 Wrap commonly-repeated calls to Spree::Config to reduce unnecessary cache reads
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.
2024-03-26 13:39:16 +00:00

26 lines
518 B
Ruby

# frozen_string_literal: true
class Api::CurrencyConfigSerializer < ActiveModel::Serializer
attributes :currency, :display_currency, :symbol, :symbol_position, :hide_cents
def currency
CurrentConfig.get(:currency)
end
def display_currency
CurrentConfig.get(:display_currency)
end
def symbol
::Money.new(1, CurrentConfig.get(:currency)).symbol
end
def symbol_position
CurrentConfig.get(:currency_symbol_position)
end
def hide_cents
CurrentConfig.get(:hide_cents)
end
end