Move db check to the Fizzy module

This commit is contained in:
Jorge Manrubia
2025-11-23 04:32:22 +01:00
committed by Jorge Manrubia
parent 6134407f5e
commit bab914d4e0
2 changed files with 27 additions and 9 deletions
+24 -3
View File
@@ -1,6 +1,27 @@
module Fizzy
def self.saas?
return @saas if defined?(@saas)
@saas = !!(ENV["SAAS"] || File.exist?(File.expand_path("../../tmp/saas.txt", __dir__)))
class << self
def saas?
return @saas if defined?(@saas)
@saas = !!(ENV["SAAS"] || File.exist?(File.expand_path("../../tmp/saas.txt", __dir__)))
end
def db_adapter
@db_adapter ||= DbAdapter.new ENV.fetch("DATABASE_ADAPTER", saas? ? "mysql" : "sqlite")
end
end
class DbAdapter
def initialize(name)
@name = name.to_s
end
def to_s
@name
end
# Not using inquiry so that it works before Rails env loads.
def sqlite?
@name == "sqlite"
end
end
end