Files
openfoodnetwork/config/initializers/spree.rb
Matt-Yorkley 6aada422fd Fix deprecation warnings around class loading during initialization
This:
```
DEPRECATION WARNING: Initialization autoloaded the constant User.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload User, for example,
the expected changes won't be reflected in that stale Class object.

This autoloaded constant has been unloaded.

In order to autoload safely at boot time, please wrap your code in a reloader
callback this way:

    Rails.application.reloader.to_prepare do
      # Autoload classes and modules needed at boot time here.
    end

That block runs when the application boots, and every time there is a reload.
For historical reasons, it may run twice, so it has to be idempotent.

Check the "Autoloading and Reloading Constants" guide to learn more about how
Rails autoloads and reloads.
```
2021-12-25 20:51:18 +00:00

43 lines
1.7 KiB
Ruby

# Configure Spree Preferences
#
# Note: Initializing preferences available within the Admin will overwrite any changes that were made through the user interface when you restart.
# If you would like users to be able to update a setting with the Admin it should NOT be set here.
#
# In order to initialize a setting do:
# config.setting_name = 'new value'
require 'spree/core'
Rails.application.reloader.to_prepare do
Spree.config do |config|
config.site_url = ENV['SITE_URL'] if ENV['SITE_URL']
config.site_name = ENV['SITE_NAME'] if ENV['SITE_NAME']
config.shipping_instructions = true
config.address_requires_state = true
config.admin_interface_logo = '/default_images/ofn-logo.png'
# S3 settings
config.s3_bucket = ENV['S3_BUCKET'] if ENV['S3_BUCKET']
config.s3_access_key = ENV['S3_ACCESS_KEY'] if ENV['S3_ACCESS_KEY']
config.s3_secret = ENV['S3_SECRET'] if ENV['S3_SECRET']
config.use_s3 = true if ENV['S3_BUCKET']
config.s3_headers = ENV['S3_HEADERS'] if ENV['S3_HEADERS']
config.s3_protocol = ENV.fetch('S3_PROTOCOL', 'https')
end
# Read mail configuration from ENV vars at boot time and ensure the values are
# applied correctly in Spree::Config.
MailConfiguration.apply!
# Attachments settings
Spree::Image.set_attachment_attribute(:path, ENV['ATTACHMENT_PATH']) if ENV['ATTACHMENT_PATH']
Spree::Image.set_attachment_attribute(:url, ENV['ATTACHMENT_URL']) if ENV['ATTACHMENT_URL']
Spree::Image.set_storage_attachment_attributes
# TODO Work out why this is necessary
# Seems like classes within OFN module become 'uninitialized' when server reloads
# unless the empty module is explicity 'registered' here. Something to do with autoloading?
module OpenFoodNetwork
end
end