From d3b06342f63d802cc16c7ab2cbf74d6f594502ca Mon Sep 17 00:00:00 2001 From: Corin Wilkins <1826895+CorinWilkins@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:12:52 +0100 Subject: [PATCH] Only generate cost centers if running in server. * initializers are always run after version 4 of rails. In this instance the initializer was being run by rake during the docker build process. However, the necessary env vars are not present at build time so this step was failing. Line 36 stops this. --- config/initializers/cost_centers.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/config/initializers/cost_centers.rb b/config/initializers/cost_centers.rb index 1714eda..dcb80c6 100644 --- a/config/initializers/cost_centers.rb +++ b/config/initializers/cost_centers.rb @@ -13,9 +13,13 @@ def load_from_s3(bucket, key) return data end +def load_dummy_cost_centres() + File.read(File.join(Rails.root, 'config', 'cost_centre_fixture.csv')) +end + def get_cost_centre_data() if Rails.env.development? - return File.read(File.join(Rails.root, 'config', 'cost_centre_fixture.csv')) + return load_dummy_cost_centres() end begin @@ -28,4 +32,7 @@ def get_cost_centre_data() end end -COST_CENTRES = CostCentreReader.new(get_cost_centre_data()) + +if defined?(Rails::Server) + COST_CENTRES = CostCentreReader.new(get_cost_centre_data()) +end