From 3bbb45e4d68714bbd5be2ed64331519423a88672 Mon Sep 17 00:00:00 2001 From: Daniel Farina Date: Mon, 12 Feb 2024 11:45:56 -0800 Subject: [PATCH 1/4] Add missing requires to CloverWeb Pre-patch, if you start `pry` and immediately try to load `CloverWeb` it will crash. --- clover_web.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clover_web.rb b/clover_web.rb index ea105d31b..2d1b17f87 100644 --- a/clover_web.rb +++ b/clover_web.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "mail" +require "roda" require "tilt" require "tilt/erubi" From 5ff765c6beef49ce78da89511abc6323c150add9 Mon Sep 17 00:00:00 2001 From: Daniel Farina Date: Mon, 12 Feb 2024 11:47:51 -0800 Subject: [PATCH 2/4] Add missing autoloaded constant name In the same vein as part of 651c3e74255078c330d9200c87fd28925a85860c, some constants are handled specially in `loader.rb`. I missed the special constant loaded by the initial Unreloader instantiation. --- loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader.rb b/loader.rb index 90a6914bd..175abdbe4 100644 --- a/loader.rb +++ b/loader.rb @@ -19,7 +19,7 @@ Unreloader.autoload("#{__dir__}/db.rb") { "DB" } Unreloader.autoload("#{__dir__}/ubid.rb") { "UBID" } -AUTOLOAD_CONSTANTS = ["DB", "UBID"] +AUTOLOAD_CONSTANTS = ["DB", "UBID", "Clover"] # Set up autoloads using Unreloader using a style much like Zeitwerk: # directories are modules, file names are classes. From 09da56ba3a9ba4567e86fd58baff1f8bdaedc94e Mon Sep 17 00:00:00 2001 From: Daniel Farina Date: Mon, 12 Feb 2024 11:56:13 -0800 Subject: [PATCH 3/4] Expand and centralize class freezing Clover isn't intended to depend on class modifications after an initial load phase. There's no reason to restrict freezing to core classes or models, and using `loader.rb`'s existing complications to itemize classes under our control to freeze is broad and economical. Note there is a small change in semantics to freezing models: previously, there were only left un-frozen in test (i.e. they were frozen in `RACK_ENV=development`), now they are only frozen when `RACK_ENV=production`. Reported-by: Burak Yucesoy <2082070+byucesoy@users.noreply.github.com> --- clover.rb | 10 ---------- loader.rb | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/clover.rb b/clover.rb index fb1ec3509..cd33cbdba 100644 --- a/clover.rb +++ b/clover.rb @@ -6,16 +6,6 @@ require "roda" class Clover < Roda - def self.freeze - # :nocov: - unless Config.test? - Sequel::Model.freeze_descendents - DB.freeze - end - # :nocov: - super - end - route do |r| r.on "api" do r.run CloverApi diff --git a/loader.rb b/loader.rb index 175abdbe4..0856e44bd 100644 --- a/loader.rb +++ b/loader.rb @@ -83,7 +83,7 @@ AUTOLOAD_CONSTANTS.freeze if Config.production? - AUTOLOAD_CONSTANTS.each { Object.const_get(_1) } + AUTOLOAD_CONSTANTS.map { Object.const_get(_1) }.each(&:freeze) end def clover_freeze From 93115cc7e32db830451c598998dbe64cd83e5ce8 Mon Sep 17 00:00:00 2001 From: Daniel Farina Date: Mon, 19 Feb 2024 17:55:10 -0800 Subject: [PATCH 4/4] Initialize class variables to nil to be able to freeze classes This works, but I wonder if there's a way to improve this with metaprogramming; it would be good if the lazy expressions in the "getters" that are cached were executed at load time, because, it would be annoying if they failed dynamically, at first call. --- lib/billing_rate.rb | 2 ++ lib/github.rb | 2 ++ model/page.rb | 2 ++ prog/postgres/postgres_resource_nexus.rb | 2 ++ 4 files changed, 8 insertions(+) diff --git a/lib/billing_rate.rb b/lib/billing_rate.rb index bac8d591e..7eebf2960 100644 --- a/lib/billing_rate.rb +++ b/lib/billing_rate.rb @@ -3,6 +3,8 @@ require "yaml" class BillingRate + @@rates = nil + def self.rates @@rates ||= YAML.load_file("config/billing_rates.yml") end diff --git a/lib/github.rb b/lib/github.rb index e42ecc491..653964cf3 100644 --- a/lib/github.rb +++ b/lib/github.rb @@ -30,6 +30,8 @@ def self.installation_client(installation_id) client end + @@runner_labels = nil + def self.runner_labels @@runner_labels ||= YAML.load_file("config/github_runner_labels.yml").to_h { [_1["name"], _1] } end diff --git a/model/page.rb b/model/page.rb index defa95583..da549c57e 100644 --- a/model/page.rb +++ b/model/page.rb @@ -16,6 +16,8 @@ def active include ResourceMethods semaphore :resolve + @@pagerduty_client = nil + def pagerduty_client @@pagerduty_client ||= Pagerduty.build(integration_key: Config.pagerduty_key, api_version: 2) end diff --git a/prog/postgres/postgres_resource_nexus.rb b/prog/postgres/postgres_resource_nexus.rb index 83a842db9..e30cb5895 100644 --- a/prog/postgres/postgres_resource_nexus.rb +++ b/prog/postgres/postgres_resource_nexus.rb @@ -210,6 +210,8 @@ def create_certificate ).map(&:to_pem) end + @@dns_zone = nil + def self.dns_zone @@dns_zone ||= DnsZone[project_id: Config.postgres_service_project_id, name: Config.postgres_service_hostname] end